Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
| 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
| 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 direction = toTextDirection(state().getDirection(), canvas()); | 749 direction = toTextDirection(state().getDirection(), canvas()); |
| 750 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion | | 750 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion | |
| 751 TextRun::ForbidLeadingExpansion, | 751 TextRun::ForbidLeadingExpansion, |
| 752 direction, false); | 752 direction, false); |
| 753 textRun.setNormalizeSpace(true); | 753 textRun.setNormalizeSpace(true); |
| 754 FloatRect textBounds = font.selectionRectForText( | 754 FloatRect textBounds = font.selectionRectForText( |
| 755 textRun, FloatPoint(), font.getFontDescription().computedSize(), 0, -1, | 755 textRun, FloatPoint(), font.getFontDescription().computedSize(), 0, -1, |
| 756 true); | 756 true); |
| 757 | 757 |
| 758 // x direction | 758 // x direction |
| 759 metrics->setWidth(font.width(textRun)); | 759 metrics->setWidth(SkScalarRoundToInt(font.width(textRun))); |
| 760 metrics->setActualBoundingBoxLeft(-textBounds.x()); | 760 metrics->setActualBoundingBoxLeft(SkScalarRoundToInt(-textBounds.x())); |
| 761 metrics->setActualBoundingBoxRight(textBounds.maxX()); | 761 metrics->setActualBoundingBoxRight(SkScalarRoundToInt(textBounds.maxX())); |
| 762 | 762 |
| 763 // y direction | 763 // y direction |
| 764 const FontMetrics& fontMetrics = font.getFontMetrics(); | 764 const FontMetrics& fontMetrics = font.getFontMetrics(); |
| 765 const float ascent = fontMetrics.floatAscent(); | 765 const float ascent = fontMetrics.ascent(); |
| 766 const float descent = fontMetrics.floatDescent(); | 766 const float descent = fontMetrics.descent(); |
| 767 const float baselineY = getFontBaseline(fontMetrics); | 767 const float baselineY = SkScalarRoundToInt(getFontBaseline(fontMetrics)); |
| 768 | 768 |
| 769 metrics->setFontBoundingBoxAscent(ascent - baselineY); | 769 metrics->setFontBoundingBoxAscent(ascent - baselineY); |
| 770 metrics->setFontBoundingBoxDescent(descent + baselineY); | 770 metrics->setFontBoundingBoxDescent(descent + baselineY); |
| 771 metrics->setActualBoundingBoxAscent(-textBounds.y() - baselineY); | 771 metrics->setActualBoundingBoxAscent(SkScalarRoundToInt(-textBounds.y()) - |
| 772 metrics->setActualBoundingBoxDescent(textBounds.maxY() + baselineY); | 772 baselineY); |
| 773 metrics->setActualBoundingBoxDescent(SkScalarRoundToInt(textBounds.maxY()) + | |
| 774 baselineY); | |
| 773 | 775 |
| 774 // Note : top/bottom and ascend/descend are currently the same, so there's no | 776 // Note : top/bottom and ascend/descend are currently the same, so there's no |
| 775 // difference between the EM box's top and bottom and the font's ascend and | 777 // difference between the EM box's top and bottom and the font's ascend and |
| 776 // descend | 778 // descend |
| 777 metrics->setEmHeightAscent(0); | 779 metrics->setEmHeightAscent(0); |
| 778 metrics->setEmHeightDescent(0); | 780 metrics->setEmHeightDescent(0); |
| 779 | 781 |
| 780 metrics->setHangingBaseline(0.8f * ascent - baselineY); | 782 metrics->setHangingBaseline(0.8f * ascent - baselineY); |
| 781 metrics->setAlphabeticBaseline(-baselineY); | 783 metrics->setAlphabeticBaseline(-baselineY); |
| 782 metrics->setIdeographicBaseline(-descent - baselineY); | 784 metrics->setIdeographicBaseline(-descent - baselineY); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 break; | 860 break; |
| 859 } | 861 } |
| 860 | 862 |
| 861 // The slop built in to this mask rect matches the heuristic used in | 863 // The slop built in to this mask rect matches the heuristic used in |
| 862 // FontCGWin.cpp for GDI text. | 864 // FontCGWin.cpp for GDI text. |
| 863 TextRunPaintInfo textRunPaintInfo(textRun); | 865 TextRunPaintInfo textRunPaintInfo(textRun); |
| 864 textRunPaintInfo.bounds = | 866 textRunPaintInfo.bounds = |
| 865 FloatRect(location.x() - fontMetrics.height() / 2, | 867 FloatRect(location.x() - fontMetrics.height() / 2, |
| 866 location.y() - fontMetrics.ascent() - fontMetrics.lineGap(), | 868 location.y() - fontMetrics.ascent() - fontMetrics.lineGap(), |
| 867 width + fontMetrics.height(), fontMetrics.lineSpacing()); | 869 width + fontMetrics.height(), fontMetrics.lineSpacing()); |
| 870 | |
| 868 if (paintType == CanvasRenderingContext2DState::StrokePaintType) | 871 if (paintType == CanvasRenderingContext2DState::StrokePaintType) |
| 869 inflateStrokeRect(textRunPaintInfo.bounds); | 872 inflateStrokeRect(textRunPaintInfo.bounds); |
| 870 | 873 |
| 871 CanvasRenderingContext2DAutoRestoreSkCanvas stateRestorer(this); | 874 CanvasRenderingContext2DAutoRestoreSkCanvas stateRestorer(this); |
| 872 if (useMaxWidth) { | 875 if (useMaxWidth) { |
| 873 drawingCanvas()->save(); | 876 drawingCanvas()->save(); |
| 874 drawingCanvas()->translate(location.x(), location.y()); | 877 drawingCanvas()->translate(location.x(), location.y()); |
| 875 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) | 878 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) |
| 876 // still work. | 879 // still work. |
| 877 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1); | 880 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 891 textRunPaintInfo.bounds, paintType); | 894 textRunPaintInfo.bounds, paintType); |
| 892 } | 895 } |
| 893 | 896 |
| 894 const Font& CanvasRenderingContext2D::accessFont() { | 897 const Font& CanvasRenderingContext2D::accessFont() { |
| 895 if (!state().hasRealizedFont()) | 898 if (!state().hasRealizedFont()) |
| 896 setFont(state().unparsedFont()); | 899 setFont(state().unparsedFont()); |
| 897 canvas()->document().canvasFontCache()->willUseCurrentFont(); | 900 canvas()->document().canvasFontCache()->willUseCurrentFont(); |
| 898 return state().font(); | 901 return state().font(); |
| 899 } | 902 } |
| 900 | 903 |
| 901 int CanvasRenderingContext2D::getFontBaseline( | 904 float CanvasRenderingContext2D::getFontBaseline( |
| 902 const FontMetrics& fontMetrics) const { | 905 const FontMetrics& fontMetrics) const { |
| 903 switch (state().getTextBaseline()) { | 906 switch (state().getTextBaseline()) { |
| 904 case TopTextBaseline: | 907 case TopTextBaseline: |
| 905 return fontMetrics.ascent(); | 908 return fontMetrics.floatAscent(); |
|
eae
2016/10/04 20:43:11
In CanvasRenderingContext2D::measureText you chang
zakerinasab1
2016/10/06 20:02:52
Fixed.
| |
| 906 case HangingTextBaseline: | 909 case HangingTextBaseline: |
| 907 // According to | 910 // According to |
| 908 // http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling | 911 // http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling |
| 909 // "FOP (Formatting Objects Processor) puts the hanging baseline at 80% of | 912 // "FOP (Formatting Objects Processor) puts the hanging baseline at 80% of |
| 910 // the ascender height" | 913 // the ascender height" |
| 911 return (fontMetrics.ascent() * 4) / 5; | 914 return (fontMetrics.floatAscent() * 4.0) / 5.0; |
| 912 case BottomTextBaseline: | 915 case BottomTextBaseline: |
| 913 case IdeographicTextBaseline: | 916 case IdeographicTextBaseline: |
| 914 return -fontMetrics.descent(); | 917 return -fontMetrics.floatDescent(); |
| 915 case MiddleTextBaseline: | 918 case MiddleTextBaseline: |
| 916 return -fontMetrics.descent() + fontMetrics.height() / 2; | 919 return -fontMetrics.floatDescent() + fontMetrics.height() / 2.0; |
| 917 case AlphabeticTextBaseline: | 920 case AlphabeticTextBaseline: |
| 918 default: | 921 default: |
| 919 // Do nothing. | 922 // Do nothing. |
| 920 break; | 923 break; |
| 921 } | 924 } |
| 922 return 0; | 925 return 0; |
| 923 } | 926 } |
| 924 | 927 |
| 925 void CanvasRenderingContext2D::setIsHidden(bool hidden) { | 928 void CanvasRenderingContext2D::setIsHidden(bool hidden) { |
| 926 if (canvas()->hasImageBuffer()) | 929 if (canvas()->hasImageBuffer()) |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 } | 1131 } |
| 1129 return true; | 1132 return true; |
| 1130 } | 1133 } |
| 1131 | 1134 |
| 1132 void CanvasRenderingContext2D::resetUsageTracking() { | 1135 void CanvasRenderingContext2D::resetUsageTracking() { |
| 1133 UsageCounters newCounters; | 1136 UsageCounters newCounters; |
| 1134 m_usageCounters = newCounters; | 1137 m_usageCounters = newCounters; |
| 1135 } | 1138 } |
| 1136 | 1139 |
| 1137 } // namespace blink | 1140 } // namespace blink |
| OLD | NEW |