本文整理汇总了C++中ZLTextWordCursor::charIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ ZLTextWordCursor::charIndex方法的具体用法?C++ ZLTextWordCursor::charIndex怎么用?C++ ZLTextWordCursor::charIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZLTextWordCursor
的用法示例。
在下文中一共展示了ZLTextWordCursor::charIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例2: cursorPosition
BookTextView::Position BookTextView::cursorPosition(const ZLTextWordCursor &cursor) const {
return Position(cursor.paragraphCursor().index(), cursor.elementIndex(), cursor.charIndex());
}
示例3: prepareTextLine
void ZLTextView::prepareTextLine(const ZLTextLineInfo &info, int y) {
y = std::min(y + info.Height, topMargin() + textAreaHeight());
myStyle.setTextStyle(info.StartStyle, info.StartBidiLevel);
int spaceCounter = info.SpaceCounter;
int fullCorrection = 0;
const bool endOfParagraph = info.End.isEndOfParagraph();
bool wordOccured = false;
int x = lineStartMargin() + info.StartIndent;
const int fontSize = myStyle.textStyle()->fontSize();
// TODO: change metrics at font change
const ZLTextStyleEntry::Metrics metrics(fontSize, fontSize / 2, viewWidth(), textAreaHeight());
switch (myStyle.textStyle()->alignment()) {
case ALIGN_RIGHT:
if (!myStyle.baseIsRtl()) {
x += metrics.FullWidth - myStyle.textStyle()->lineEndIndent(metrics, myStyle.baseIsRtl()) - info.Width;
}
break;
case ALIGN_LEFT:
if (myStyle.baseIsRtl()) {
x += metrics.FullWidth - myStyle.textStyle()->lineEndIndent(metrics, myStyle.baseIsRtl()) - info.Width;
}
break;
case ALIGN_LINESTART:
break;
case ALIGN_CENTER:
x += (metrics.FullWidth - myStyle.textStyle()->lineEndIndent(metrics, myStyle.baseIsRtl()) - info.Width) / 2;
break;
case ALIGN_JUSTIFY:
if (!endOfParagraph && (info.End.element().kind() != ZLTextElement::AFTER_PARAGRAPH_ELEMENT)) {
fullCorrection = metrics.FullWidth - myStyle.textStyle()->lineEndIndent(metrics, myStyle.baseIsRtl()) - info.Width;
}
break;
case ALIGN_UNDEFINED:
break;
}
const ZLTextParagraphCursor ¶graph = info.RealStart.paragraphCursor();
int paragraphIndex = paragraph.index();
for (ZLTextWordCursor pos = info.RealStart; !pos.equalElementIndex(info.End); pos.nextWord()) {
const ZLTextElement &element = paragraph[pos.elementIndex()];
ZLTextElement::Kind kind = element.kind();
int width = myStyle.elementWidth(element, pos.charIndex(), metrics);
myStyle.applySingleControl(element);
switch (kind) {
case ZLTextElement::WORD_ELEMENT:
case ZLTextElement::IMAGE_ELEMENT:
{
const int height = myStyle.elementHeight(element, metrics);
const int descent = myStyle.elementDescent(element);
const int length = (kind == ZLTextElement::WORD_ELEMENT) ? ((const ZLTextWord&)element).Length - pos.charIndex() : 0;
addAreaToTextMap(
ZLTextElementArea(
paragraphIndex, pos.elementIndex(), pos.charIndex(), length, false,
myStyle.textStyle(), kind,
x, x + width - 1, y - height + 1, y + descent, myStyle.bidiLevel()
)
);
wordOccured = true;
break;
}
case ZLTextElement::CONTROL_ELEMENT:
case ZLTextElement::FORCED_CONTROL_ELEMENT:
break;
case ZLTextElement::HSPACE_ELEMENT:
case ZLTextElement::NB_HSPACE_ELEMENT:
if (wordOccured && (spaceCounter > 0)) {
int correction = fullCorrection / spaceCounter;
x += context().spaceWidth() + correction;
fullCorrection -= correction;
wordOccured = false;
--spaceCounter;
}
break;
case ZLTextElement::INDENT_ELEMENT:
case ZLTextElement::BEFORE_PARAGRAPH_ELEMENT:
case ZLTextElement::AFTER_PARAGRAPH_ELEMENT:
case ZLTextElement::EMPTY_LINE_ELEMENT:
case ZLTextElement::FIXED_HSPACE_ELEMENT:
break;
case ZLTextElement::START_REVERSED_SEQUENCE_ELEMENT:
//context().setColor(ZLColor(0, 255, 0));
//context().drawLine(visualX(x), y, visualX(x), y - 20);
break;
case ZLTextElement::END_REVERSED_SEQUENCE_ELEMENT:
flushRevertedElements(myStyle.bidiLevel());
//context().setColor(ZLColor(255, 0, 0));
//context().drawLine(visualX(x), y, visualX(x), y - 20);
break;
}
x += width;
}
if (!endOfParagraph && (info.End.element().kind() == ZLTextElement::WORD_ELEMENT)) {
int start = 0;
if (info.End.equalElementIndex(info.RealStart)) {
//.........这里部分代码省略.........
示例4: 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;
}
}