void ListMarkerPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (paintInfo.phase != PaintPhaseForeground) return; if (m_layoutListMarker.style()->visibility() != EVisibility::Visible) return; if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( paintInfo.context, m_layoutListMarker, paintInfo.phase)) return; LayoutPoint boxOrigin(paintOffset + m_layoutListMarker.location()); LayoutRect overflowRect(m_layoutListMarker.visualOverflowRect()); overflowRect.moveBy(boxOrigin); IntRect pixelSnappedOverflowRect = pixelSnappedIntRect(overflowRect); if (!paintInfo.cullRect().intersectsCullRect(overflowRect)) return; LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutListMarker, paintInfo.phase, pixelSnappedOverflowRect); LayoutRect box(boxOrigin, m_layoutListMarker.size()); IntRect marker = m_layoutListMarker.getRelativeMarkerRect(); marker.moveBy(roundedIntPoint(boxOrigin)); GraphicsContext& context = paintInfo.context; if (m_layoutListMarker.isImage()) { context.drawImage(m_layoutListMarker.image() ->image(m_layoutListMarker, marker.size(), m_layoutListMarker.styleRef().effectiveZoom()) .get(), marker); if (m_layoutListMarker.getSelectionState() != SelectionNone) { LayoutRect selRect = m_layoutListMarker.localSelectionRect(); selRect.moveBy(boxOrigin); context.fillRect( pixelSnappedIntRect(selRect), m_layoutListMarker.listItem()->selectionBackgroundColor()); } return; } LayoutListMarker::ListStyleCategory styleCategory = m_layoutListMarker.getListStyleCategory(); if (styleCategory == LayoutListMarker::ListStyleCategory::None) return; Color color(m_layoutListMarker.resolveColor(CSSPropertyColor)); if (BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( m_layoutListMarker.styleRef(), m_layoutListMarker.listItem()->document())) color = TextPainter::textColorForWhiteBackground(color); // Apply the color to the list marker text. context.setFillColor(color); const EListStyleType listStyle = m_layoutListMarker.style()->listStyleType(); if (styleCategory == LayoutListMarker::ListStyleCategory::Symbol) { paintSymbol(context, color, marker, listStyle); return; } if (m_layoutListMarker.text().isEmpty()) return; const Font& font = m_layoutListMarker.style()->font(); TextRun textRun = constructTextRun(font, m_layoutListMarker.text(), m_layoutListMarker.styleRef()); GraphicsContextStateSaver stateSaver(context, false); if (!m_layoutListMarker.style()->isHorizontalWritingMode()) { marker.moveBy(roundedIntPoint(-boxOrigin)); marker = marker.transposedRect(); marker.moveBy( IntPoint(roundToInt(box.x()), roundToInt(box.y() - m_layoutListMarker.logicalHeight()))); stateSaver.save(); context.translate(marker.x(), marker.maxY()); context.rotate(static_cast<float>(deg2rad(90.))); context.translate(-marker.x(), -marker.maxY()); } TextRunPaintInfo textRunPaintInfo(textRun); textRunPaintInfo.bounds = marker; const SimpleFontData* fontData = m_layoutListMarker.style()->font().primaryFont(); IntPoint textOrigin = IntPoint( marker.x(), marker.y() + (fontData ? fontData->getFontMetrics().ascent() : 0)); // Text is not arbitrary. We can judge whether it's RTL from the first // character, and we only need to handle the direction RightToLeft for now. bool textNeedsReversing = WTF::Unicode::direction(m_layoutListMarker.text()[0]) == WTF::Unicode::RightToLeft; StringBuilder reversedText; if (textNeedsReversing) { unsigned length = m_layoutListMarker.text().length(); reversedText.reserveCapacity(length); for (int i = length - 1; i >= 0; --i) reversedText.append(m_layoutListMarker.text()[i]); DCHECK(reversedText.length() == length); textRun.setText(reversedText.toString()); } const UChar suffix = ListMarkerText::suffix(listStyle, m_layoutListMarker.listItem()->value()); UChar suffixStr[2] = {suffix, static_cast<UChar>(' ')}; TextRun suffixRun = constructTextRun(font, suffixStr, 2, m_layoutListMarker.styleRef(), m_layoutListMarker.style()->direction()); TextRunPaintInfo suffixRunInfo(suffixRun); suffixRunInfo.bounds = marker; if (m_layoutListMarker.style()->isLeftToRightDirection()) { context.drawText(font, textRunPaintInfo, textOrigin); context.drawText(font, suffixRunInfo, textOrigin + IntSize(font.width(textRun), 0)); } else { context.drawText(font, suffixRunInfo, textOrigin); context.drawText(font, textRunPaintInfo, textOrigin + IntSize(font.width(suffixRun), 0)); } }
void Legend::paintSymbols(QPointF pos) { qreal x = pos.x(); qreal y = pos.y(); x += 30; switch(m_Orientation) { case Legend::LO_HORIZONTAL : { // paint Open Cluster/Asterism symbol QString label1 = i18n("Open Cluster") + "\n" + i18n("Asterism"); paintSymbol(QPointF(x, y), 3, 1, 0, label1); x += m_XSymbolSpacing; // paint Globular Cluster symbol paintSymbol(QPointF(x, y), 4, 1, 0, i18n("Globular Cluster")); x += m_XSymbolSpacing; // paint Gaseous Nebula/Dark Nebula symbol QString label3 = i18n("Gaseous Nebula") + "\n" + i18n("Dark Nebula"); paintSymbol(QPointF(x, y), 5, 1, 0, label3); x += m_XSymbolSpacing; // paint Planetary Nebula symbol paintSymbol(QPointF(x, y), 6, 1, 0, i18n("Planetary Nebula")); x += m_XSymbolSpacing; // paint Supernova Remnant paintSymbol(QPointF(x, y), 7, 1, 0, i18n("Supernova Remnant")); x += m_XSymbolSpacing; // paint Galaxy/Quasar QString label6 = i18n("Galaxy") + "\n" + i18n("Quasar"); paintSymbol(QPointF(x, y), 8, 0.5, 60, label6); x += m_XSymbolSpacing; // paint Galaxy Cluster paintSymbol(QPointF(x, y), 14, 1, 0, i18n("Galactic Cluster")); break; } case Legend::LO_VERTICAL : { // paint Open Cluster/Asterism symbol QString label1 = i18n("Open Cluster") + "\n" + i18n("Asterism"); paintSymbol(QPointF(x, y), 3, 1, 0, label1); y += m_YSymbolSpacing; // paint Globular Cluster symbol paintSymbol(QPointF(x, y), 4, 1, 0, i18n("Globular Cluster")); y += m_YSymbolSpacing; // paint Gaseous Nebula/Dark Nebula symbol QString label3 = i18n("Gaseous Nebula") + "\n" + i18n("Dark Nebula"); paintSymbol(QPointF(x, y), 5, 1, 0, label3); y += m_YSymbolSpacing; // paint Planetary Nebula symbol paintSymbol(QPointF(x, y), 6, 1, 0, i18n("Planetary Nebula")); y += m_YSymbolSpacing; // paint Supernova Remnant paintSymbol(QPointF(x, y), 7, 1, 0, i18n("Supernova Remnant")); y += m_YSymbolSpacing; // paint Galaxy/Quasar QString label6 = i18n("Galaxy") + "\n" + i18n("Quasar"); paintSymbol(QPointF(x, y), 8, 0.5, 60, label6); y += m_YSymbolSpacing; // paint Galaxy Cluster paintSymbol(QPointF(x, y), 14, 1, 0, i18n("Galactic Cluster")); break; } default : return; // should never happen } }