RESize REPainter::SizeOfText(const std::string& textUTF8, const std::string& fontNameUTF8, unsigned int flags, float size) { QFont::Weight weight = (flags & REPainter::Bold ? QFont::Bold : QFont::Normal); QFont font(QString::fromStdString(fontNameUTF8), size, weight, flags & REPainter::Italic); font.setPixelSize(size); QFontMetrics fm(font); int qflags = Qt::AlignLeft | Qt::AlignTop | Qt::TextDontClip | Qt::TextSingleLine; return RESize(fm.size(qflags, QString::fromStdString(textUTF8))); }
RESize RESize::fromString(const REString & string) { if (string.length() > 0) { RESize s; if (REStringUtilsPrivate::readArrayF32(string.UTF8String(), s.size, 2, ';') == 2) { return s; } } return RESize(); }
RESize RESize::fromString(const char * string) { if (string) { RESize s; if (REStringUtilsPrivate::readArrayF32(string, s.size, 2, ';') == 2) { return s; } } return RESize(); }
RESize RELabelRETextLineBreakGeneratorPrivate::TextSize(REArray<RETTFFontChar *> * charsArr, REFontObject * font, const REFloat32 charsSpaceRatio) { if (charsArr && font) { RESize size(0.0f, 0.0f); RESize ratio(font->getCharsScaleRatio()); for (REUInt32 i = 0; i < charsArr->count(); i++) { RETTFFontChar * fontChar = (*charsArr)[i]; size.width += ((ratio.width * fontChar->offsetX) * charsSpaceRatio); size.width += (ratio.width * fontChar->advanceX); const REFloat32 height = (ratio.height * fontChar->height); if (size.height < height) { size.height = height; } } return size; } return RESize(0.0f, 0.0f); }
RESize RELabelRETextLineBreakGeneratorPrivate::TruncMiddle(REArray<RETTFFontChar *> * resultChars, REArray<RETTFFontChar *> * allChars, REArray<RETTFFontChar *> * dotsChars, REFontObject * font, const REFloat32 maxWidth, const REFloat32 dotsCharsWidth, const REFloat32 charsSpaceRatio) { if (resultChars && allChars && dotsChars && font) { RESize size(0.0f, 0.0f); RESize ratio(font->getCharsScaleRatio()); if (allChars->isEmpty()) { return size; } RERange leftRange(0, 0); RERange rightRange(0, 0); REUInt32 leftIndex = 0; REUInt32 rightIndex = (allChars->count() - 1); REBOOL isLeft = true; REUInt32 processedCharsCount = 0; while (1) { RETTFFontChar * fontChar = isLeft ? (*allChars)[leftIndex] : (*allChars)[rightIndex]; REFloat32 width = ((ratio.width * fontChar->offsetX) * charsSpaceRatio); width += (ratio.width * fontChar->advanceX); const REFloat32 totalWidth = size.width + width + dotsCharsWidth; if (totalWidth < maxWidth) { if (isLeft) { leftRange.length++; } else { rightRange.length++; rightRange.location = rightIndex; } size.width += width; } else { break; } processedCharsCount++; if (processedCharsCount == allChars->count()) { break; } if (isLeft) { leftIndex++; } else { rightIndex--; } isLeft = !isLeft; } if ((leftRange.length > 0) || (rightRange.length > 0)) { for (REUInt32 i = 0; i < leftRange.length; i++) { RETTFFontChar * fontChar = (*allChars)[i]; resultChars->add(fontChar); } for (REUInt32 i = 0; i < dotsChars->count(); i++) { RETTFFontChar * dotChar = (*dotsChars)[i]; resultChars->add(dotChar); REFloat32 dotWidth = ((ratio.width * dotChar->offsetX) * charsSpaceRatio); dotWidth += (ratio.width * dotChar->advanceX); size.width += dotWidth; } for (REUInt32 i = 0; i < rightRange.length; i++) { RETTFFontChar * fontChar = (*allChars)[rightRange.location]; resultChars->add(fontChar); rightRange.location++; } } return size; } return RESize(0.0f, 0.0f); }
RESize RELabelRETextLineBreakGeneratorPrivate::TruncTailOrHead(REArray<RETTFFontChar *> * resultChars, REArray<RETTFFontChar *> * allChars, REArray<RETTFFontChar *> * dotsChars, REFontObject * font, const REFloat32 maxWidth, const REFloat32 dotsCharsWidth, const REFloat32 charsSpaceRatio, const REBOOL isAddDotsLast) { if (resultChars && allChars && dotsChars && font) { RESize size(0.0f, 0.0f); REUInt32 index = 0; if (allChars->count()) { if (!isAddDotsLast) { index = (allChars->count() - 1); } } else { return size; } RESize ratio(font->getCharsScaleRatio()); REBOOL isIterating = true; while (isIterating) { RETTFFontChar * fontChar = (*allChars)[index]; REFloat32 width = ((ratio.width * fontChar->offsetX) * charsSpaceRatio); width += (ratio.width * fontChar->advanceX); const REFloat32 totalWidth = size.width + width + dotsCharsWidth; if (totalWidth < maxWidth) { if (isAddDotsLast) { resultChars->add(fontChar); } else { resultChars->insert(0, fontChar); } size.width += width; } else { if (resultChars->count() && dotsChars->count()) { REUInt32 j = 0; REBOOL isAdding = true; if (!isAddDotsLast) { j = (dotsChars->count() - 1); } while (isAdding) { RETTFFontChar * dotChar = (*dotsChars)[j]; if (isAddDotsLast) { resultChars->add(dotChar); } else { resultChars->insert(0, dotChar); } REFloat32 dotWidth = ((ratio.width * dotChar->offsetX) * charsSpaceRatio); dotWidth += (ratio.width * dotChar->advanceX); size.width += dotWidth; if (isAddDotsLast) { j++; isAdding = (j < dotsChars->count()); } else if (j) { j--; } else { isAdding = false; } } } return size; } if (isAddDotsLast) { index++; isIterating = (index < allChars->count()); } else if (index) { index--; } else { isIterating = false; } } return size; } return RESize(0.0f, 0.0f); }