OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. | 2 * Copyright (c) 2007, 2008, 2010 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 119 } |
120 | 120 |
121 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, | 121 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, |
122 const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, | 122 const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, |
123 const FloatPoint& point, const FloatRect& textRect) const | 123 const FloatPoint& point, const FloatRect& textRect) const |
124 { | 124 { |
125 SkScalar x = SkFloatToScalar(point.x()); | 125 SkScalar x = SkFloatToScalar(point.x()); |
126 SkScalar y = SkFloatToScalar(point.y()); | 126 SkScalar y = SkFloatToScalar(point.y()); |
127 | 127 |
128 const OpenTypeVerticalData* verticalData = font->verticalData(); | 128 const OpenTypeVerticalData* verticalData = font->verticalData(); |
129 if (font->platformData().orientation() == Vertical && verticalData) { | 129 bool drawVertically = font->platformData().orientation() == Vertical && vert icalData; |
130 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); | |
131 SkPoint* pos = storage.get(); | |
132 | 130 |
133 AffineTransform savedMatrix = gc->getCTM(); | 131 AffineTransform savedMatrix = gc->getCTM(); |
132 if (drawVertically) { | |
eae
2014/10/01 15:39:50
Could you move this down to line 150 so that it is
| |
134 gc->concatCTM(AffineTransform(0, -1, 1, 0, point.x(), point.y())); | 133 gc->concatCTM(AffineTransform(0, -1, 1, 0, point.x(), point.y())); |
135 gc->concatCTM(AffineTransform(1, 0, 0, 1, -point.x(), -point.y())); | 134 gc->concatCTM(AffineTransform(1, 0, 0, 1, -point.x(), -point.y())); |
136 | |
137 const unsigned kMaxBufferLength = 256; | |
138 Vector<FloatPoint, kMaxBufferLength> translations; | |
139 | |
140 const FontMetrics& metrics = font->fontMetrics(); | |
141 SkScalar verticalOriginX = SkFloatToScalar(point.x() + metrics.floatAsce nt() - metrics.floatAscent(IdeographicBaseline)); | |
142 float horizontalOffset = point.x(); | |
143 | |
144 unsigned glyphIndex = 0; | |
145 while (glyphIndex < numGlyphs) { | |
146 unsigned chunkLength = std::min(kMaxBufferLength, numGlyphs - glyphI ndex); | |
147 | |
148 const Glyph* glyphs = glyphBuffer.glyphs(from + glyphIndex); | |
149 translations.resize(chunkLength); | |
150 verticalData->getVerticalTranslationsForGlyphs(font, &glyphs[0], chu nkLength, reinterpret_cast<float*>(&translations[0])); | |
151 | |
152 x = verticalOriginX; | |
153 y = SkFloatToScalar(point.y() + horizontalOffset - point.x()); | |
154 | |
155 float currentWidth = 0; | |
156 for (unsigned i = 0; i < chunkLength; ++i, ++glyphIndex) { | |
157 pos[i].set( | |
158 x + SkIntToScalar(lroundf(translations[i].x())), | |
159 y + -SkIntToScalar(-lroundf(currentWidth - translations[i].y ()))); | |
160 currentWidth += glyphBuffer.advanceAt(from + glyphIndex); | |
161 } | |
162 horizontalOffset += currentWidth; | |
163 paintGlyphs(gc, font, glyphs, chunkLength, pos, textRect); | |
164 } | |
165 | |
166 gc->setCTM(savedMatrix); | |
167 return; | |
168 } | 135 } |
169 | 136 |
170 if (!glyphBuffer.hasOffsets()) { | 137 if (!glyphBuffer.hasOffsets()) { |
138 ASSERT(!drawVertically); | |
171 SkAutoSTMalloc<64, SkScalar> storage(numGlyphs); | 139 SkAutoSTMalloc<64, SkScalar> storage(numGlyphs); |
172 SkScalar* xpos = storage.get(); | 140 SkScalar* xpos = storage.get(); |
173 const float* adv = glyphBuffer.advances(from); | 141 const float* adv = glyphBuffer.advances(from); |
174 for (unsigned i = 0; i < numGlyphs; i++) { | 142 for (unsigned i = 0; i < numGlyphs; i++) { |
175 xpos[i] = x; | 143 xpos[i] = x; |
176 x += SkFloatToScalar(adv[i]); | 144 x += SkFloatToScalar(adv[i]); |
177 } | 145 } |
178 const Glyph* glyphs = glyphBuffer.glyphs(from); | 146 const Glyph* glyphs = glyphBuffer.glyphs(from); |
179 paintGlyphsHorizontal(gc, font, glyphs, numGlyphs, xpos, SkFloatToScalar (y), textRect); | 147 paintGlyphsHorizontal(gc, font, glyphs, numGlyphs, xpos, SkFloatToScalar (y), textRect); |
180 return; | 148 return; |
181 } | 149 } |
182 | 150 |
183 ASSERT(glyphBuffer.hasOffsets()); | 151 ASSERT(glyphBuffer.hasOffsets()); |
184 const GlyphBufferWithOffsets& glyphBufferWithOffsets = | 152 const GlyphBufferWithOffsets& glyphBufferWithOffsets = |
185 static_cast<const GlyphBufferWithOffsets&>(glyphBuffer); | 153 static_cast<const GlyphBufferWithOffsets&>(glyphBuffer); |
186 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); | 154 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); |
187 SkPoint* pos = storage.get(); | 155 SkPoint* pos = storage.get(); |
188 const FloatSize* offsets = glyphBufferWithOffsets.offsets(from); | 156 const FloatSize* offsets = glyphBufferWithOffsets.offsets(from); |
189 const float* advances = glyphBufferWithOffsets.advances(from); | 157 const float* advances = glyphBufferWithOffsets.advances(from); |
190 SkScalar advanceSoFar = SkFloatToScalar(0); | 158 SkScalar advanceSoFar = SkFloatToScalar(0); |
191 for (unsigned i = 0; i < numGlyphs; i++) { | 159 if (drawVertically) { |
192 pos[i].set( | 160 const FontMetrics& metrics = font->fontMetrics(); |
193 x + SkFloatToScalar(offsets[i].width()) + advanceSoFar, | 161 x += SkFloatToScalar(metrics.floatAscent() - metrics.floatAscent(Ideogra phicBaseline)); |
194 y + SkFloatToScalar(offsets[i].height())); | 162 for (unsigned i = 0; i < numGlyphs; i++) { |
195 advanceSoFar += SkFloatToScalar(advances[i]); | 163 pos[i].set( |
164 x + SkFloatToScalar(offsets[i].width()), | |
165 y + SkFloatToScalar(offsets[i].height()) + advanceSoFar); | |
166 advanceSoFar += SkFloatToScalar(advances[i]); | |
167 } | |
168 } else { | |
169 for (unsigned i = 0; i < numGlyphs; i++) { | |
170 pos[i].set( | |
171 x + SkFloatToScalar(offsets[i].width()) + advanceSoFar, | |
172 y + SkFloatToScalar(offsets[i].height())); | |
173 advanceSoFar += SkFloatToScalar(advances[i]); | |
174 } | |
196 } | 175 } |
197 | 176 |
198 const Glyph* glyphs = glyphBufferWithOffsets.glyphs(from); | 177 const Glyph* glyphs = glyphBufferWithOffsets.glyphs(from); |
199 paintGlyphs(gc, font, glyphs, numGlyphs, pos, textRect); | 178 paintGlyphs(gc, font, glyphs, numGlyphs, pos, textRect); |
179 | |
180 if (drawVertically) { | |
181 gc->setCTM(savedMatrix); | |
182 } | |
200 } | 183 } |
201 | 184 |
202 void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi nt& origin) const | 185 void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi nt& origin) const |
203 { | 186 { |
204 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); | 187 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); |
205 | 188 |
206 // FIXME: It would be good to move this to Font.cpp, if we're sure that none | 189 // FIXME: It would be good to move this to Font.cpp, if we're sure that none |
207 // of the things in FontMac's setupPaint need to apply here. | 190 // of the things in FontMac's setupPaint need to apply here. |
208 // See also paintGlyphs. | 191 // See also paintGlyphs. |
209 TextDrawingModeFlags textMode = gc->textDrawingMode(); | 192 TextDrawingModeFlags textMode = gc->textDrawingMode(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 buffer.pos[j] = x; | 327 buffer.pos[j] = x; |
345 x += SkFloatToScalar(advances[j]); | 328 x += SkFloatToScalar(advances[j]); |
346 } | 329 } |
347 } | 330 } |
348 | 331 |
349 advance = x; | 332 advance = x; |
350 return adoptRef(builder.build()); | 333 return adoptRef(builder.build()); |
351 } | 334 } |
352 | 335 |
353 } // namespace blink | 336 } // namespace blink |
OLD | NEW |