| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (codePathToUse != ComplexPath) | 220 if (codePathToUse != ComplexPath) |
| 221 return buildTextBlobForSimpleText(runInfo, textOrigin, couldUseLCDRender
edText); | 221 return buildTextBlobForSimpleText(runInfo, textOrigin, couldUseLCDRender
edText); |
| 222 | 222 |
| 223 return nullptr; | 223 return nullptr; |
| 224 } | 224 } |
| 225 | 225 |
| 226 PassTextBlobPtr Font::buildTextBlobForSimpleText(const TextRunPaintInfo& runInfo
, const FloatPoint& textOrigin, bool couldUseLCDRenderedText) const | 226 PassTextBlobPtr Font::buildTextBlobForSimpleText(const TextRunPaintInfo& runInfo
, const FloatPoint& textOrigin, bool couldUseLCDRenderedText) const |
| 227 { | 227 { |
| 228 GlyphBuffer glyphBuffer; | 228 GlyphBuffer glyphBuffer; |
| 229 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo, glyphBuffe
r); | 229 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo, glyphBuffe
r); |
| 230 ASSERT(!glyphBuffer.hasVerticalAdvances()); | |
| 231 | 230 |
| 232 if (glyphBuffer.isEmpty()) | 231 if (glyphBuffer.isEmpty()) |
| 233 return nullptr; | 232 return nullptr; |
| 234 | 233 |
| 235 FloatRect blobBounds = runInfo.bounds; | 234 FloatRect blobBounds = runInfo.bounds; |
| 236 blobBounds.moveBy(-textOrigin); | 235 blobBounds.moveBy(-textOrigin); |
| 237 | 236 |
| 238 float ignoredWidth; | 237 float ignoredWidth; |
| 239 return buildTextBlob(glyphBuffer, initialAdvance, blobBounds, ignoredWidth,
couldUseLCDRenderedText); | 238 return buildTextBlob(glyphBuffer, initialAdvance, blobBounds, ignoredWidth,
couldUseLCDRenderedText); |
| 240 } | 239 } |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 681 } |
| 683 | 682 |
| 684 return initialAdvance; | 683 return initialAdvance; |
| 685 } | 684 } |
| 686 | 685 |
| 687 float Font::drawSimpleText(GraphicsContext* context, const TextRunPaintInfo& run
Info, const FloatPoint& point) const | 686 float Font::drawSimpleText(GraphicsContext* context, const TextRunPaintInfo& run
Info, const FloatPoint& point) const |
| 688 { | 687 { |
| 689 // This glyph buffer holds our glyphs+advances+font data for each glyph. | 688 // This glyph buffer holds our glyphs+advances+font data for each glyph. |
| 690 GlyphBuffer glyphBuffer; | 689 GlyphBuffer glyphBuffer; |
| 691 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo, glyphBuffe
r); | 690 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo, glyphBuffe
r); |
| 692 ASSERT(!glyphBuffer.hasVerticalAdvances()); | |
| 693 | 691 |
| 694 if (glyphBuffer.isEmpty()) | 692 if (glyphBuffer.isEmpty()) |
| 695 return 0; | 693 return 0; |
| 696 | 694 |
| 697 TextBlobPtr textBlob; | 695 TextBlobPtr textBlob; |
| 698 float advance = 0; | 696 float advance = 0; |
| 699 if (RuntimeEnabledFeatures::textBlobEnabled()) { | 697 if (RuntimeEnabledFeatures::textBlobEnabled()) { |
| 700 // Using text blob causes a small difference in how gradients and | 698 // Using text blob causes a small difference in how gradients and |
| 701 // patterns are rendered. | 699 // patterns are rendered. |
| 702 // FIXME: Fix this, most likely in Skia. | 700 // FIXME: Fix this, most likely in Skia. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 725 return; | 723 return; |
| 726 | 724 |
| 727 drawEmphasisMarks(context, runInfo, glyphBuffer, mark, FloatPoint(point.x()
+ initialAdvance, point.y())); | 725 drawEmphasisMarks(context, runInfo, glyphBuffer, mark, FloatPoint(point.x()
+ initialAdvance, point.y())); |
| 728 } | 726 } |
| 729 | 727 |
| 730 float Font::drawGlyphBuffer(GraphicsContext* context, const TextRunPaintInfo& ru
nInfo, const GlyphBuffer& glyphBuffer, const FloatPoint& point) const | 728 float Font::drawGlyphBuffer(GraphicsContext* context, const TextRunPaintInfo& ru
nInfo, const GlyphBuffer& glyphBuffer, const FloatPoint& point) const |
| 731 { | 729 { |
| 732 // Draw each contiguous run of glyphs that use the same font data. | 730 // Draw each contiguous run of glyphs that use the same font data. |
| 733 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0); | 731 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0); |
| 734 FloatPoint startPoint(point); | 732 FloatPoint startPoint(point); |
| 735 FloatPoint nextPoint = startPoint + glyphBuffer.advanceAt(0); | 733 float advanceSoFar = 0; |
| 736 unsigned lastFrom = 0; | 734 unsigned lastFrom = 0; |
| 737 unsigned nextGlyph = 1; | 735 unsigned nextGlyph = 0; |
| 738 #if ENABLE(SVG_FONTS) | 736 #if ENABLE(SVG_FONTS) |
| 739 TextRun::RenderingContext* renderingContext = runInfo.run.renderingContext()
; | 737 TextRun::RenderingContext* renderingContext = runInfo.run.renderingContext()
; |
| 740 #endif | 738 #endif |
| 741 | 739 |
| 742 float widthSoFar = 0; | |
| 743 widthSoFar += glyphBuffer.advanceAt(0).width(); | |
| 744 while (nextGlyph < glyphBuffer.size()) { | 740 while (nextGlyph < glyphBuffer.size()) { |
| 745 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph); | 741 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph); |
| 746 | 742 |
| 747 if (nextFontData != fontData) { | 743 if (nextFontData != fontData) { |
| 748 #if ENABLE(SVG_FONTS) | 744 #if ENABLE(SVG_FONTS) |
| 749 if (renderingContext && fontData->isSVGFont()) | 745 if (renderingContext && fontData->isSVGFont()) |
| 750 renderingContext->drawSVGGlyphs(context, runInfo.run, fontData,
glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint); | 746 renderingContext->drawSVGGlyphs(context, runInfo.run, fontData,
glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint); |
| 751 else | 747 else |
| 752 #endif | 748 #endif |
| 753 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph -
lastFrom, startPoint, runInfo.bounds); | 749 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph -
lastFrom, startPoint, runInfo.bounds); |
| 754 | 750 |
| 755 lastFrom = nextGlyph; | 751 lastFrom = nextGlyph; |
| 756 fontData = nextFontData; | 752 fontData = nextFontData; |
| 757 startPoint = nextPoint; | 753 startPoint += FloatSize(advanceSoFar, 0); |
| 754 advanceSoFar = 0; |
| 758 } | 755 } |
| 759 nextPoint += glyphBuffer.advanceAt(nextGlyph); | 756 advanceSoFar += glyphBuffer.advanceAt(nextGlyph); |
| 760 widthSoFar += glyphBuffer.advanceAt(nextGlyph).width(); | |
| 761 nextGlyph++; | 757 nextGlyph++; |
| 762 } | 758 } |
| 763 | 759 |
| 764 #if ENABLE(SVG_FONTS) | 760 #if ENABLE(SVG_FONTS) |
| 765 if (renderingContext && fontData->isSVGFont()) | 761 if (renderingContext && fontData->isSVGFont()) |
| 766 renderingContext->drawSVGGlyphs(context, runInfo.run, fontData, glyphBuf
fer, lastFrom, nextGlyph - lastFrom, startPoint); | 762 renderingContext->drawSVGGlyphs(context, runInfo.run, fontData, glyphBuf
fer, lastFrom, nextGlyph - lastFrom, startPoint); |
| 767 else | 763 else |
| 768 #endif | 764 #endif |
| 769 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFro
m, startPoint, runInfo.bounds); | 765 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFro
m, startPoint, runInfo.bounds); |
| 770 return widthSoFar; | 766 |
| 767 startPoint += FloatSize(advanceSoFar, 0); |
| 768 return startPoint.x() - point.x(); |
| 771 } | 769 } |
| 772 | 770 |
| 773 inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph
glyph) | 771 inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph
glyph) |
| 774 { | 772 { |
| 775 if (fontData->platformData().orientation() == Horizontal) { | 773 if (fontData->platformData().orientation() == Horizontal) { |
| 776 FloatRect bounds = fontData->boundsForGlyph(glyph); | 774 FloatRect bounds = fontData->boundsForGlyph(glyph); |
| 777 return bounds.x() + bounds.width() / 2; | 775 return bounds.x() + bounds.width() / 2; |
| 778 } | 776 } |
| 779 // FIXME: Use glyph bounds once they make sense for vertical fonts. | 777 // FIXME: Use glyph bounds once they make sense for vertical fonts. |
| 780 return fontData->widthForGlyph(glyph) / 2; | 778 return fontData->widthForGlyph(glyph) / 2; |
| 781 } | 779 } |
| 782 | 780 |
| 783 inline static float offsetToMiddleOfAdvanceAtIndex(const GlyphBuffer& glyphBuffe
r, size_t i) | 781 inline static float offsetToMiddleOfAdvanceAtIndex(const GlyphBuffer& glyphBuffe
r, size_t i) |
| 784 { | 782 { |
| 785 return glyphBuffer.advanceAt(i).width() / 2; | 783 return glyphBuffer.advanceAt(i) / 2; |
| 786 } | 784 } |
| 787 | 785 |
| 788 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& r
unInfo, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoi
nt& point) const | 786 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& r
unInfo, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoi
nt& point) const |
| 789 { | 787 { |
| 790 FontCachePurgePreventer purgePreventer; | 788 FontCachePurgePreventer purgePreventer; |
| 791 | 789 |
| 792 GlyphData markGlyphData; | 790 GlyphData markGlyphData; |
| 793 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) | 791 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) |
| 794 return; | 792 return; |
| 795 | 793 |
| 796 const SimpleFontData* markFontData = markGlyphData.fontData; | 794 const SimpleFontData* markFontData = markGlyphData.fontData; |
| 797 ASSERT(markFontData); | 795 ASSERT(markFontData); |
| 798 if (!markFontData) | 796 if (!markFontData) |
| 799 return; | 797 return; |
| 800 | 798 |
| 801 Glyph markGlyph = markGlyphData.glyph; | 799 Glyph markGlyph = markGlyphData.glyph; |
| 802 Glyph spaceGlyph = markFontData->spaceGlyph(); | 800 Glyph spaceGlyph = markFontData->spaceGlyph(); |
| 803 | 801 |
| 804 float middleOfLastGlyph = offsetToMiddleOfAdvanceAtIndex(glyphBuffer, 0); | 802 float middleOfLastGlyph = offsetToMiddleOfAdvanceAtIndex(glyphBuffer, 0); |
| 805 FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph(
markFontData, markGlyph), point.y()); | 803 FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph(
markFontData, markGlyph), point.y()); |
| 806 | 804 |
| 807 GlyphBuffer markBuffer; | 805 GlyphBuffer markBuffer; |
| 808 for (unsigned i = 0; i + 1 < glyphBuffer.size(); ++i) { | 806 for (unsigned i = 0; i + 1 < glyphBuffer.size(); ++i) { |
| 809 float middleOfNextGlyph = offsetToMiddleOfAdvanceAtIndex(glyphBuffer, i
+ 1); | 807 float middleOfNextGlyph = offsetToMiddleOfAdvanceAtIndex(glyphBuffer, i
+ 1); |
| 810 float advance = glyphBuffer.advanceAt(i).width() - middleOfLastGlyph + m
iddleOfNextGlyph; | 808 float advance = glyphBuffer.advanceAt(i) - middleOfLastGlyph + middleOfN
extGlyph; |
| 811 markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFont
Data, advance); | 809 markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFont
Data, advance); |
| 812 middleOfLastGlyph = middleOfNextGlyph; | 810 middleOfLastGlyph = middleOfNextGlyph; |
| 813 } | 811 } |
| 814 markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spa
ceGlyph, markFontData, 0); | 812 markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spa
ceGlyph, markFontData, 0); |
| 815 | 813 |
| 816 drawGlyphBuffer(context, runInfo, markBuffer, startPoint); | 814 drawGlyphBuffer(context, runInfo, markBuffer, startPoint); |
| 817 } | 815 } |
| 818 | 816 |
| 819 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
Data*>* fallbackFonts, IntRectExtent* glyphBounds) const | 817 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
Data*>* fallbackFonts, IntRectExtent* glyphBounds) const |
| 820 { | 818 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 if (delta <= 0) | 895 if (delta <= 0) |
| 898 break; | 896 break; |
| 899 } | 897 } |
| 900 } | 898 } |
| 901 } | 899 } |
| 902 | 900 |
| 903 return offset; | 901 return offset; |
| 904 } | 902 } |
| 905 | 903 |
| 906 } // namespace blink | 904 } // namespace blink |
| OLD | NEW |