QString CompareSideBySideView::getText(SourceElementDiffOperation *source, const EDiff::KDiff state, const bool isEmpty) { if(isEmpty) { return "" ; } QString text; bool useText = false ; switch(state) { default: { QString msg = tr("Unknown state:%1 in setup diff").arg(state); Utils::error(msg); CompareError(msg); } break; case EDiff::ED_ADDED: useText = true ; break; case EDiff::ED_MODIFIED: useText = true ; break; case EDiff::ED_EQUAL: useText = true ; break; case EDiff::ED_DELETED: useText = true ; break; } if(useText) { Element *element = source->element(); switch(element->getType()) { case Element::ET_ELEMENT: text = QString("<%1>").arg(element->tag()); break; case Element::ET_PROCESSING_INSTRUCTION: text = QString("<? %1 %2 ?>").arg(element->getPITarget()).arg(element->getPIData()); break; case Element::ET_COMMENT: text = getElidedText(element->text); text = QString("Comment: %1").arg(text); break; case Element::ET_TEXT: text = getElidedText(element->text); if(element->isCDATA()) { text = QString("Text CDATA: [[%1]]").arg(text); } else { text = QString("Text: %1").arg(text); } break; default: break; } } return text ; }
//---------------------------------------------------------------- // calcTextBBox // static void calcTextBBox(const Text & item, BBox & bbox, double maxWidth, double maxHeight) { QFont font = item.font_; double fontSize = item.fontSize_.get(); double supersample = item.supersample_.get(); font.setPointSizeF(fontSize * supersample); QFontMetricsF fm(font); QRectF maxRect(0.0, 0.0, maxWidth * supersample, maxHeight * supersample); int flags = item.textFlags(); QString text = getElidedText(maxWidth * supersample, item, fm, flags); QRectF rect = fm.boundingRect(maxRect, flags, text); bbox.x_ = rect.x() / supersample; bbox.y_ = rect.y() / supersample; bbox.w_ = rect.width() / supersample; bbox.h_ = rect.height() / supersample; }
//---------------------------------------------------------------- // Text::TPrivate::uploadTexture // bool Text::TPrivate::uploadTexture(const Text & item) { QRectF maxRect; getMaxRect(item, maxRect); double supersample = item.supersample_.get(); maxRect.setWidth(maxRect.width() * supersample); maxRect.setHeight(maxRect.height() * supersample); BBox bboxContent; item.Item::get(kPropertyBBoxContent, bboxContent); iw_ = (int)ceil(bboxContent.w_ * supersample); ih_ = (int)ceil(bboxContent.h_ * supersample); if (!(iw_ && ih_)) { return true; } GLsizei widthPowerOfTwo = powerOfTwoGEQ<GLsizei>(iw_); GLsizei heightPowerOfTwo = powerOfTwoGEQ<GLsizei>(ih_); QImage img(widthPowerOfTwo, heightPowerOfTwo, QImage::Format_ARGB32); { const Color & color = item.color_.get(); #ifndef _WIN32 Color bg = color.transparent(); #else const Color & bg = item.background_.get(); #endif img.fill(QColor(bg).rgba()); QPainter painter(&img); QFont font = item.font_; double fontSize = item.fontSize_.get(); font.setPointSizeF(fontSize * supersample); painter.setFont(font); QFontMetricsF fm(font); int flags = item.textFlags(); QString text = getElidedText(maxRect.width(), item, fm, flags); painter.setPen(QColor(color)); painter.drawText(maxRect, flags, text); } // do not upload supersampled texture at full size, scale down first: downsample_ = downsampleImage(img, supersample); bool ok = yae::uploadTexture2D(img, texId_, supersample == 1.0 ? GL_NEAREST : GL_LINEAR_MIPMAP_LINEAR); return ok; }