OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 SkAutoSTArray<kLocalGlyphMax * 2, SkScalar> storage(numGlyphs); | 76 SkAutoSTArray<kLocalGlyphMax * 2, SkScalar> storage(numGlyphs); |
77 SkScalar* xpos = storage.get(); | 77 SkScalar* xpos = storage.get(); |
78 for (unsigned i = 0; i < numGlyphs; i++) { | 78 for (unsigned i = 0; i < numGlyphs; i++) { |
79 xpos[i] = x; | 79 xpos[i] = x; |
80 x += SkIntToScalar(advances[i]); | 80 x += SkIntToScalar(advances[i]); |
81 } | 81 } |
82 context->drawPosTextH(glyphs, numGlyphs * sizeof(uint16_t), xpos, y, tex
tRect, *paint); | 82 context->drawPosTextH(glyphs, numGlyphs * sizeof(uint16_t), xpos, y, tex
tRect, *paint); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 static void paintSkiaText(GraphicsContext* context, | 86 void paintSkiaText(GraphicsContext* context, |
87 const FontPlatformData& data, | 87 const FontPlatformData& data, |
88 SkTypeface* face, float size, uint32_t textFlags, | |
89 unsigned numGlyphs, | 88 unsigned numGlyphs, |
90 const WORD* glyphs, | 89 const WORD* glyphs, |
91 const int* advances, | 90 const int* advances, |
92 const GOFFSET* offsets, | 91 const GOFFSET* offsets, |
93 const SkPoint& origin, | 92 const SkPoint& origin, |
94 const SkRect& textRect) | 93 const SkRect& textRect) |
95 { | 94 { |
96 TextDrawingModeFlags textMode = context->textDrawingMode(); | 95 TextDrawingModeFlags textMode = context->textDrawingMode(); |
97 | 96 |
98 // Filling (if necessary). This is the common case. | 97 // Filling (if necessary). This is the common case. |
99 SkPaint paint; | 98 SkPaint paint; |
100 context->setupPaintForFilling(&paint); | 99 context->setupPaintForFilling(&paint); |
101 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 100 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
102 data.setupPaint(&paint, context); | 101 data.setupPaint(&paint, context); |
103 | 102 |
104 // FIXME: Only needed to support the HFONT based paintSkiaText | |
105 // version where a new typeface is created from the HFONT. | |
106 // As such it can go away once the HFONT code path is removed. | |
107 paint.setTypeface(face); | |
108 | |
109 bool didFill = false; | 103 bool didFill = false; |
110 | 104 |
111 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get
Looper())) { | 105 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get
Looper())) { |
112 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); | 106 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); |
113 didFill = true; | 107 didFill = true; |
114 } | 108 } |
115 | 109 |
116 // Stroking on top (if necessary). | 110 // Stroking on top (if necessary). |
117 if ((textMode & TextModeStroke) | 111 if ((textMode & TextModeStroke) |
118 && context->strokeStyle() != NoStroke | 112 && context->strokeStyle() != NoStroke |
119 && context->strokeThickness() > 0) { | 113 && context->strokeThickness() > 0) { |
120 | 114 |
121 paint.reset(); | 115 paint.reset(); |
122 context->setupPaintForStroking(&paint); | 116 context->setupPaintForStroking(&paint); |
123 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 117 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
124 data.setupPaint(&paint, context); | 118 data.setupPaint(&paint, context); |
125 paint.setTypeface(face); | |
126 | 119 |
127 if (didFill) { | 120 if (didFill) { |
128 // If there is a shadow and we filled above, there will already be | 121 // If there is a shadow and we filled above, there will already be |
129 // a shadow. We don't want to draw it again or it will be too dark | 122 // a shadow. We don't want to draw it again or it will be too dark |
130 // and it will go on top of the fill. | 123 // and it will go on top of the fill. |
131 // | 124 // |
132 // Note that this isn't strictly correct, since the stroke could be | 125 // Note that this isn't strictly correct, since the stroke could be |
133 // very thick and the shadow wouldn't account for this. The "right" | 126 // very thick and the shadow wouldn't account for this. The "right" |
134 // thing would be to draw to a new layer and then draw that layer | 127 // thing would be to draw to a new layer and then draw that layer |
135 // with a shadow. But this is a lot of extra work for something | 128 // with a shadow. But this is a lot of extra work for something |
136 // that isn't normally an issue. | 129 // that isn't normally an issue. |
137 paint.setLooper(0); | 130 paint.setLooper(0); |
138 } | 131 } |
139 | 132 |
140 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); | 133 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); |
141 } | 134 } |
142 } | 135 } |
143 | 136 |
144 ////////////////////////////////////////////////////////////////////////////////
/////////// | |
145 | |
146 void paintSkiaText(GraphicsContext* context, | |
147 const FontPlatformData& data, | |
148 unsigned numGlyphs, | |
149 const WORD* glyphs, | |
150 const int* advances, | |
151 const GOFFSET* offsets, | |
152 const SkPoint& origin, | |
153 const SkRect& textRect) | |
154 { | |
155 paintSkiaText(context, data, data.typeface(), data.size(), data.paintTextFla
gs(), | |
156 numGlyphs, glyphs, advances, offsets, origin, textRect); | |
157 } | |
158 | |
159 } // namespace WebCore | 137 } // namespace WebCore |
OLD | NEW |