| 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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 | 822 |
| 823 // Currently, SkPictureImageFilter does not support subpixel text | 823 // Currently, SkPictureImageFilter does not support subpixel text |
| 824 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we | 824 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we |
| 825 // need to fall out of display list mode when drawing text to an opaque | 825 // need to fall out of display list mode when drawing text to an opaque |
| 826 // canvas. crbug.com/583809 | 826 // canvas. crbug.com/583809 |
| 827 if (!creationAttributes().alpha() && !isAccelerated()) | 827 if (!creationAttributes().alpha() && !isAccelerated()) |
| 828 canvas()->disableDeferral( | 828 canvas()->disableDeferral( |
| 829 DisableDeferralReasonSubPixelTextAntiAliasingSupport); | 829 DisableDeferralReasonSubPixelTextAntiAliasingSupport); |
| 830 | 830 |
| 831 const Font& font = accessFont(); | 831 const Font& font = accessFont(); |
| 832 font.getFontDescription().setSubpixelAscentDescent(true); |
| 832 if (!font.primaryFont()) | 833 if (!font.primaryFont()) |
| 833 return; | 834 return; |
| 834 | 835 |
| 835 const FontMetrics& fontMetrics = font.getFontMetrics(); | 836 const FontMetrics& fontMetrics = font.getFontMetrics(); |
| 836 | 837 |
| 837 // FIXME: Need to turn off font smoothing. | 838 // FIXME: Need to turn off font smoothing. |
| 838 | 839 |
| 839 const ComputedStyle* computedStyle = 0; | 840 const ComputedStyle* computedStyle = 0; |
| 840 TextDirection direction = | 841 TextDirection direction = |
| 841 toTextDirection(state().getDirection(), canvas(), &computedStyle); | 842 toTextDirection(state().getDirection(), canvas(), &computedStyle); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 textRunPaintInfo.bounds, paintType); | 904 textRunPaintInfo.bounds, paintType); |
| 904 } | 905 } |
| 905 | 906 |
| 906 const Font& CanvasRenderingContext2D::accessFont() { | 907 const Font& CanvasRenderingContext2D::accessFont() { |
| 907 if (!state().hasRealizedFont()) | 908 if (!state().hasRealizedFont()) |
| 908 setFont(state().unparsedFont()); | 909 setFont(state().unparsedFont()); |
| 909 canvas()->document().canvasFontCache()->willUseCurrentFont(); | 910 canvas()->document().canvasFontCache()->willUseCurrentFont(); |
| 910 return state().font(); | 911 return state().font(); |
| 911 } | 912 } |
| 912 | 913 |
| 913 int CanvasRenderingContext2D::getFontBaseline( | 914 float CanvasRenderingContext2D::getFontBaseline( |
| 914 const FontMetrics& fontMetrics) const { | 915 const FontMetrics& fontMetrics) const { |
| 916 // If the font is so tiny that the lroundf operations result in two |
| 917 // different types of text baselines to return the same baseline, use |
| 918 // floating point metrics (crbug.com/338908). |
| 919 // If you changed the heuristic here, for consistency please also change it |
| 920 // in SimpleFontData::platformInit(). |
| 921 bool useFloatAscentDescent = |
| 922 fontMetrics.ascent() < 3 || fontMetrics.height() < 2; |
| 915 switch (state().getTextBaseline()) { | 923 switch (state().getTextBaseline()) { |
| 916 case TopTextBaseline: | 924 case TopTextBaseline: |
| 917 return fontMetrics.ascent(); | 925 return useFloatAscentDescent ? fontMetrics.floatAscent() |
| 926 : fontMetrics.ascent(); |
| 918 case HangingTextBaseline: | 927 case HangingTextBaseline: |
| 919 // According to | 928 // According to |
| 920 // http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling | 929 // http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling |
| 921 // "FOP (Formatting Objects Processor) puts the hanging baseline at 80% of | 930 // "FOP (Formatting Objects Processor) puts the hanging baseline at 80% of |
| 922 // the ascender height" | 931 // the ascender height" |
| 923 return (fontMetrics.ascent() * 4) / 5; | 932 return useFloatAscentDescent ? (fontMetrics.floatAscent() * 4.0) / 5.0 |
| 933 : (fontMetrics.ascent() * 4) / 5; |
| 924 case BottomTextBaseline: | 934 case BottomTextBaseline: |
| 925 case IdeographicTextBaseline: | 935 case IdeographicTextBaseline: |
| 926 return -fontMetrics.descent(); | 936 return useFloatAscentDescent ? -fontMetrics.floatDescent() |
| 937 : -fontMetrics.descent(); |
| 927 case MiddleTextBaseline: | 938 case MiddleTextBaseline: |
| 928 return -fontMetrics.descent() + fontMetrics.height() / 2; | 939 return useFloatAscentDescent |
| 940 ? -fontMetrics.floatDescent() + fontMetrics.floatHeight() / 2.0 |
| 941 : -fontMetrics.descent() + fontMetrics.height() / 2; |
| 929 case AlphabeticTextBaseline: | 942 case AlphabeticTextBaseline: |
| 930 default: | 943 default: |
| 931 // Do nothing. | 944 // Do nothing. |
| 932 break; | 945 break; |
| 933 } | 946 } |
| 934 return 0; | 947 return 0; |
| 935 } | 948 } |
| 936 | 949 |
| 937 void CanvasRenderingContext2D::setIsHidden(bool hidden) { | 950 void CanvasRenderingContext2D::setIsHidden(bool hidden) { |
| 938 if (canvas()->hasImageBuffer()) | 951 if (canvas()->hasImageBuffer()) |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 } | 1153 } |
| 1141 return true; | 1154 return true; |
| 1142 } | 1155 } |
| 1143 | 1156 |
| 1144 void CanvasRenderingContext2D::resetUsageTracking() { | 1157 void CanvasRenderingContext2D::resetUsageTracking() { |
| 1145 UsageCounters newCounters; | 1158 UsageCounters newCounters; |
| 1146 m_usageCounters = newCounters; | 1159 m_usageCounters = newCounters; |
| 1147 } | 1160 } |
| 1148 | 1161 |
| 1149 } // namespace blink | 1162 } // namespace blink |
| OLD | NEW |