Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: Source/platform/fonts/harfbuzz/FontHarfBuzz.cpp

Issue 607483002: Separate advance from offset in GlypBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: w/fix for emphasis Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 verticalData->getVerticalTranslationsForGlyphs(font, &glyphs[0], chu nkLength, reinterpret_cast<float*>(&translations[0])); 150 verticalData->getVerticalTranslationsForGlyphs(font, &glyphs[0], chu nkLength, reinterpret_cast<float*>(&translations[0]));
151 151
152 x = verticalOriginX; 152 x = verticalOriginX;
153 y = SkFloatToScalar(point.y() + horizontalOffset - point.x()); 153 y = SkFloatToScalar(point.y() + horizontalOffset - point.x());
154 154
155 float currentWidth = 0; 155 float currentWidth = 0;
156 for (unsigned i = 0; i < chunkLength; ++i, ++glyphIndex) { 156 for (unsigned i = 0; i < chunkLength; ++i, ++glyphIndex) {
157 pos[i].set( 157 pos[i].set(
158 x + SkIntToScalar(lroundf(translations[i].x())), 158 x + SkIntToScalar(lroundf(translations[i].x())),
159 y + -SkIntToScalar(-lroundf(currentWidth - translations[i].y ()))); 159 y + -SkIntToScalar(-lroundf(currentWidth - translations[i].y ())));
160 currentWidth += glyphBuffer.advanceAt(from + glyphIndex).width() ; 160 currentWidth += glyphBuffer.advanceAt(from + glyphIndex);
161 } 161 }
162 horizontalOffset += currentWidth; 162 horizontalOffset += currentWidth;
163 paintGlyphs(gc, font, glyphs, chunkLength, pos, textRect); 163 paintGlyphs(gc, font, glyphs, chunkLength, pos, textRect);
164 } 164 }
165 165
166 gc->setCTM(savedMatrix); 166 gc->setCTM(savedMatrix);
167 return; 167 return;
168 } 168 }
169 169
170 if (!glyphBuffer.hasVerticalAdvances()) {
171 SkAutoSTMalloc<64, SkScalar> storage(numGlyphs);
172 SkScalar* xpos = storage.get();
173 const FloatSize* adv = glyphBuffer.advances(from);
174 for (unsigned i = 0; i < numGlyphs; i++) {
175 xpos[i] = x;
176 x += SkFloatToScalar(adv[i].width());
177 }
178 const Glyph* glyphs = glyphBuffer.glyphs(from);
179 paintGlyphsHorizontal(gc, font, glyphs, numGlyphs, xpos, SkFloatToScalar (y), textRect);
180 return;
181 }
182
183 // FIXME: text rendering speed: 170 // FIXME: text rendering speed:
Dominik Röttsches 2014/09/26 11:58:53 Do you wanna remove this obsolete comment while we
eae 2014/09/26 11:59:50 Done.
184 // Android has code in their WebCore fork to special case when the 171 // Android has code in their WebCore fork to special case when the
185 // GlyphBuffer has no advances other than the defaults. In that case the 172 // GlyphBuffer has no advances other than the defaults. In that case the
186 // text drawing can proceed faster. However, it's unclear when those 173 // text drawing can proceed faster. However, it's unclear when those
187 // patches may be upstreamed to WebKit so we always use the slower path 174 // patches may be upstreamed to WebKit so we always use the slower path
188 // here. 175 // here.
176 if (!glyphBuffer.hasOffsets()) {
177 SkAutoSTMalloc<64, SkScalar> storage(numGlyphs);
178 SkScalar* xpos = storage.get();
179 const float* adv = glyphBuffer.advances(from);
180 for (unsigned i = 0; i < numGlyphs; i++) {
181 xpos[i] = x;
182 x += SkFloatToScalar(adv[i]);
183 }
184 const Glyph* glyphs = glyphBuffer.glyphs(from);
185 paintGlyphsHorizontal(gc, font, glyphs, numGlyphs, xpos, SkFloatToScalar (y), textRect);
186 return;
187 }
188
189 ASSERT(glyphBuffer.hasOffsets());
190 const GlyphBufferWithOffsets& glyphBufferWithOffsets =
191 static_cast<const GlyphBufferWithOffsets&>(glyphBuffer);
189 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); 192 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs);
190 SkPoint* pos = storage.get(); 193 SkPoint* pos = storage.get();
191 const FloatSize* adv = glyphBuffer.advances(from); 194 const FloatSize* offsets = glyphBufferWithOffsets.offsets(from);
195 const float* advances = glyphBufferWithOffsets.advances(from);
196 SkScalar advanceSoFar = SkFloatToScalar(0);
192 for (unsigned i = 0; i < numGlyphs; i++) { 197 for (unsigned i = 0; i < numGlyphs; i++) {
193 pos[i].set(x, y); 198 pos[i].set(
194 x += SkFloatToScalar(adv[i].width()); 199 x + SkFloatToScalar(offsets[i].width()) + advanceSoFar,
195 y += SkFloatToScalar(adv[i].height()); 200 y + SkFloatToScalar(offsets[i].height()));
201 advanceSoFar += SkFloatToScalar(advances[i]);
196 } 202 }
197 203
198 const Glyph* glyphs = glyphBuffer.glyphs(from); 204 const Glyph* glyphs = glyphBufferWithOffsets.glyphs(from);
199 paintGlyphs(gc, font, glyphs, numGlyphs, pos, textRect); 205 paintGlyphs(gc, font, glyphs, numGlyphs, pos, textRect);
200 } 206 }
201 207
202 void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi nt& origin) const 208 void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi nt& origin) const
203 { 209 {
204 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); 210 ASSERT(RuntimeEnabledFeatures::textBlobEnabled());
205 211
206 // FIXME: It would be good to move this to Font.cpp, if we're sure that none 212 // 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. 213 // of the things in FontMac's setupPaint need to apply here.
208 // See also paintGlyphs. 214 // See also paintGlyphs.
(...skipping 15 matching lines...) Expand all
224 if (!runInfo.run.length()) 230 if (!runInfo.run.length())
225 return 0; 231 return 0;
226 232
227 TextDrawingModeFlags textMode = gc->textDrawingMode(); 233 TextDrawingModeFlags textMode = gc->textDrawingMode();
228 bool fill = textMode & TextModeFill; 234 bool fill = textMode & TextModeFill;
229 bool stroke = (textMode & TextModeStroke) && gc->hasStroke(); 235 bool stroke = (textMode & TextModeStroke) && gc->hasStroke();
230 236
231 if (!fill && !stroke) 237 if (!fill && !stroke)
232 return 0; 238 return 0;
233 239
234 GlyphBuffer glyphBuffer; 240 GlyphBufferWithOffsets glyphBuffer;
235 HarfBuzzShaper shaper(this, runInfo.run); 241 HarfBuzzShaper shaper(this, runInfo.run);
236 shaper.setDrawRange(runInfo.from, runInfo.to); 242 shaper.setDrawRange(runInfo.from, runInfo.to);
237 if (!shaper.shape(&glyphBuffer) || glyphBuffer.isEmpty()) 243 if (!shaper.shape(&glyphBuffer) || glyphBuffer.isEmpty())
238 return 0; 244 return 0;
239 FloatPoint adjustedPoint = shaper.adjustStartPoint(point); 245 return drawGlyphBuffer(gc, runInfo, glyphBuffer, point);
240 return drawGlyphBuffer(gc, runInfo, glyphBuffer, adjustedPoint);
241 } 246 }
242 247
243 void Font::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextR unPaintInfo& runInfo, const AtomicString& mark, const FloatPoint& point) const 248 void Font::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextR unPaintInfo& runInfo, const AtomicString& mark, const FloatPoint& point) const
244 { 249 {
245 GlyphBuffer glyphBuffer; 250 GlyphBuffer glyphBuffer;
246 251
247 float initialAdvance = getGlyphsAndAdvancesForComplexText(runInfo, glyphBuff er, ForTextEmphasis); 252 float initialAdvance = getGlyphsAndAdvancesForComplexText(runInfo, glyphBuff er, ForTextEmphasis);
248 253
249 if (glyphBuffer.isEmpty()) 254 if (glyphBuffer.isEmpty())
250 return; 255 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return shaper.selectionRect(point, height, from, to); 300 return shaper.selectionRect(point, height, from, to);
296 } 301 }
297 302
298 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia lAdvance, 303 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia lAdvance,
299 const FloatRect& bounds, float& advance, bool couldUseLCD) const 304 const FloatRect& bounds, float& advance, bool couldUseLCD) const
300 { 305 {
301 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); 306 ASSERT(RuntimeEnabledFeatures::textBlobEnabled());
302 307
303 // FIXME: Except for setupPaint, this is not specific to FontHarfBuzz. 308 // FIXME: Except for setupPaint, this is not specific to FontHarfBuzz.
304 // FIXME: Also implement the more general full-positioning path. 309 // FIXME: Also implement the more general full-positioning path.
305 ASSERT(!glyphBuffer.hasVerticalAdvances());
306 310
307 SkTextBlobBuilder builder; 311 SkTextBlobBuilder builder;
308 SkScalar x = SkFloatToScalar(initialAdvance); 312 SkScalar x = SkFloatToScalar(initialAdvance);
309 SkRect skBounds = bounds; 313 SkRect skBounds = bounds;
310 314
311 unsigned i = 0; 315 unsigned i = 0;
312 while (i < glyphBuffer.size()) { 316 while (i < glyphBuffer.size()) {
313 const SimpleFontData* fontData = glyphBuffer.fontDataAt(i); 317 const SimpleFontData* fontData = glyphBuffer.fontDataAt(i);
314 318
315 // FIXME: Handle vertical text. 319 // FIXME: Handle vertical text.
(...skipping 17 matching lines...) Expand all
333 unsigned start = i++; 337 unsigned start = i++;
334 while (i < glyphBuffer.size() && glyphBuffer.fontDataAt(i) == fontData) 338 while (i < glyphBuffer.size() && glyphBuffer.fontDataAt(i) == fontData)
335 i++; 339 i++;
336 unsigned count = i - start; 340 unsigned count = i - start;
337 341
338 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPosH(paint, count, 0, &skBounds); 342 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPosH(paint, count, 0, &skBounds);
339 343
340 const uint16_t* glyphs = glyphBuffer.glyphs(start); 344 const uint16_t* glyphs = glyphBuffer.glyphs(start);
341 std::copy(glyphs, glyphs + count, buffer.glyphs); 345 std::copy(glyphs, glyphs + count, buffer.glyphs);
342 346
343 const FloatSize* advances = glyphBuffer.advances(start); 347 const float* advances = glyphBuffer.advances(start);
344 for (unsigned j = 0; j < count; j++) { 348 for (unsigned j = 0; j < count; j++) {
345 buffer.pos[j] = x; 349 buffer.pos[j] = x;
346 x += SkFloatToScalar(advances[j].width()); 350 x += SkFloatToScalar(advances[j]);
347 } 351 }
348 } 352 }
349 353
350 advance = x; 354 advance = x;
351 return adoptRef(builder.build()); 355 return adoptRef(builder.build());
352 } 356 }
353 357
354 } // namespace blink 358 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698