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