当前位置: 首页>>代码示例>>C++>>正文


C++ ZLTextWordCursor::sameElementAs方法代码示例

本文整理汇总了C++中ZLTextWordCursor::sameElementAs方法的典型用法代码示例。如果您正苦于以下问题:C++ ZLTextWordCursor::sameElementAs方法的具体用法?C++ ZLTextWordCursor::sameElementAs怎么用?C++ ZLTextWordCursor::sameElementAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZLTextWordCursor的用法示例。


在下文中一共展示了ZLTextWordCursor::sameElementAs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: text

// Added by John to enable caller to get text from current visible page.
void ZLTextSelectionModel::text(std::string & text, int max)
{
    text.clear();
    ZLTextWordCursor start = myView.startCursor();
    ZLTextWordCursor end = myView.endCursor();
    ZLTextWordCursor cursor = start;
    while (cursor < end)
    {
        if (cursor.isEndOfParagraph())
        {
            cursor.nextParagraph();
            continue;
        }
        const ZLTextElement &element = cursor.element();
        switch (element.kind())
        {
        case ZLTextElement::WORD_ELEMENT:
            {
                const ZLTextWord &word = (const ZLTextWord&)element;
                if (cursor.sameElementAs(end))
                {
                    if (start.sameElementAs(end))
                    {
                        int skip = ZLUnicodeUtil::length(word.Data, start.charIndex());
                        int length = ZLUnicodeUtil::length(word.Data, end.charIndex()) - skip;
                        text.append(word.Data + skip, length);
                    }
                    else
                    {
                        text.append(word.Data, ZLUnicodeUtil::length(word.Data, end.charIndex()));
                    }
                }
                else if (cursor.charIndex() == 0)
                {
                    text.append(word.Data, word.Size);
                }
                else /* cursor == start */
                {
                    int skip = ZLUnicodeUtil::length(word.Data, cursor.charIndex());
                    text.append(word.Data + skip, word.Size - skip);
                }
            }
            break;
        case ZLTextElement::HSPACE_ELEMENT:
        case ZLTextElement::NB_HSPACE_ELEMENT:
            {
                text += ' ';
            }
            break;
        }
        cursor.nextWord();
        if (text.size() >= max)
        {
            return;
        }
    }
}
开发者ID:chenhbzl,项目名称:BooxApp,代码行数:58,代码来源:ZLTextSelectionModel.cpp

示例2: createData

void ZLTextSelectionModel::createData() const {
	if (!myTextIsUpToDate && !isEmpty()) {
		Range r = internalRange();

		ZLTextWordCursor start = myArea.startCursor();
		start.moveToParagraph(r.first.ParagraphIndex);
		start.moveTo(r.first.ElementIndex, r.first.CharIndex);

		ZLTextWordCursor end = myArea.startCursor();
		end.moveToParagraph(r.second.ParagraphIndex);
		end.moveTo(r.second.ElementIndex, r.second.CharIndex);

		std::set<ZLTextParagraphCursorPtr> pcursors;
		pcursors.insert(start.paragraphCursorPtr());

		ZLTextWordCursor cursor = start;
		while (cursor < end) {
			if (cursor.isEndOfParagraph()) {
				cursor.nextParagraph();
				pcursors.insert(cursor.paragraphCursorPtr());
				myText.append(ZLibrary::EndOfLine);
				continue;
			}
			const ZLTextElement &element = cursor.element();
			switch (element.kind()) {
				case ZLTextElement::WORD_ELEMENT:
				{
					const ZLTextWord &word = (const ZLTextWord&)element;
					if (cursor.sameElementAs(end)) {
						if (start.sameElementAs(end)) {
							int skip = ZLUnicodeUtil::length(word.Data, start.charIndex());
							int length = ZLUnicodeUtil::length(word.Data, end.charIndex()) - skip;
							myText.append(word.Data + skip, length);
						} else {
							myText.append(word.Data, ZLUnicodeUtil::length(word.Data, end.charIndex()));
						}
					} else if (cursor.charIndex() == 0) {
						myText.append(word.Data, word.Size);
					} else /* cursor == start */ {
						int skip = ZLUnicodeUtil::length(word.Data, cursor.charIndex());
						myText.append(word.Data + skip, word.Size - skip);
					}
					break;
				}
				case ZLTextElement::IMAGE_ELEMENT:
					if (myImage.isNull()) {
						myImage = ((const ZLTextImageElement&)element).image();
					}
					break;
				case ZLTextElement::HSPACE_ELEMENT:
				case ZLTextElement::NB_HSPACE_ELEMENT:
					myText += ' ';
					break;
				default:
					break;
			}
			cursor.nextWord();
		}
		if ((cursor == end) && !cursor.isEndOfParagraph() && myImage.isNull()) {
			const ZLTextElement &element = cursor.element();
			if (element.kind() == ZLTextElement::IMAGE_ELEMENT) {
				myImage = ((const ZLTextImageElement&)element).image();
			}
		}

		myCursors.swap(pcursors);
		myTextIsUpToDate = true;
	}
}
开发者ID:euroelessar,项目名称:FBReader,代码行数:69,代码来源:ZLTextSelectionModel.cpp


注:本文中的ZLTextWordCursor::sameElementAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。