Chromium Code Reviews| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()) { | 170 if (!glyphBuffer.hasOffsets()) { |
| 171 SkAutoSTMalloc<64, SkScalar> storage(numGlyphs); | 171 SkAutoSTMalloc<64, SkScalar> storage(numGlyphs); |
| 172 SkScalar* xpos = storage.get(); | 172 SkScalar* xpos = storage.get(); |
| 173 const FloatSize* adv = glyphBuffer.advances(from); | 173 const float* adv = glyphBuffer.advances(from); |
| 174 for (unsigned i = 0; i < numGlyphs; i++) { | 174 for (unsigned i = 0; i < numGlyphs; i++) { |
| 175 xpos[i] = x; | 175 xpos[i] = x; |
| 176 x += SkFloatToScalar(adv[i].width()); | 176 x += SkFloatToScalar(adv[i]); |
| 177 } | 177 } |
| 178 const Glyph* glyphs = glyphBuffer.glyphs(from); | 178 const Glyph* glyphs = glyphBuffer.glyphs(from); |
| 179 paintGlyphsHorizontal(gc, font, glyphs, numGlyphs, xpos, SkFloatToScalar (y), textRect); | 179 paintGlyphsHorizontal(gc, font, glyphs, numGlyphs, xpos, SkFloatToScalar (y), textRect); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // FIXME: text rendering speed: | 183 // FIXME: text rendering speed: |
| 184 // Android has code in their WebCore fork to special case when the | 184 // 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 | 185 // GlyphBuffer has no advances other than the defaults. In that case the |
| 186 // text drawing can proceed faster. However, it's unclear when those | 186 // 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 | 187 // patches may be upstreamed to WebKit so we always use the slower path |
| 188 // here. | 188 // here. |
| 189 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); | 189 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); |
| 190 SkPoint* pos = storage.get(); | 190 SkPoint* pos = storage.get(); |
| 191 const FloatSize* adv = glyphBuffer.advances(from); | 191 const FloatSize* offsets = glyphBuffer.offsets(from); |
| 192 const float* advances = glyphBuffer.advances(from); | |
| 193 SkScalar advanceSoFar = SkFloatToScalar(0); | |
| 192 for (unsigned i = 0; i < numGlyphs; i++) { | 194 for (unsigned i = 0; i < numGlyphs; i++) { |
| 193 pos[i].set(x, y); | 195 pos[i].set( |
| 194 x += SkFloatToScalar(adv[i].width()); | 196 x + SkFloatToScalar(offsets[i].width()) + advanceSoFar, |
| 195 y += SkFloatToScalar(adv[i].height()); | 197 y + SkFloatToScalar(offsets[i].height())); |
| 198 advanceSoFar += SkFloatToScalar(advances[i]); | |
| 196 } | 199 } |
| 197 | 200 |
| 198 const Glyph* glyphs = glyphBuffer.glyphs(from); | 201 const Glyph* glyphs = glyphBuffer.glyphs(from); |
| 199 paintGlyphs(gc, font, glyphs, numGlyphs, pos, textRect); | 202 paintGlyphs(gc, font, glyphs, numGlyphs, pos, textRect); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi nt& origin) const | 205 void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi nt& origin) const |
| 203 { | 206 { |
| 204 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); | 207 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); |
| 205 | 208 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 229 bool stroke = (textMode & TextModeStroke) && gc->hasStroke(); | 232 bool stroke = (textMode & TextModeStroke) && gc->hasStroke(); |
| 230 | 233 |
| 231 if (!fill && !stroke) | 234 if (!fill && !stroke) |
| 232 return 0; | 235 return 0; |
| 233 | 236 |
| 234 GlyphBuffer glyphBuffer; | 237 GlyphBuffer glyphBuffer; |
| 235 HarfBuzzShaper shaper(this, runInfo.run); | 238 HarfBuzzShaper shaper(this, runInfo.run); |
| 236 shaper.setDrawRange(runInfo.from, runInfo.to); | 239 shaper.setDrawRange(runInfo.from, runInfo.to); |
| 237 if (!shaper.shape(&glyphBuffer) || glyphBuffer.isEmpty()) | 240 if (!shaper.shape(&glyphBuffer) || glyphBuffer.isEmpty()) |
| 238 return 0; | 241 return 0; |
| 239 FloatPoint adjustedPoint = shaper.adjustStartPoint(point); | 242 return drawGlyphBuffer(gc, runInfo, glyphBuffer, point); |
| 240 return drawGlyphBuffer(gc, runInfo, glyphBuffer, adjustedPoint); | |
| 241 } | 243 } |
| 242 | 244 |
| 243 void Font::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextR unPaintInfo& runInfo, const AtomicString& mark, const FloatPoint& point) const | 245 void Font::drawEmphasisMarksForComplexText(GraphicsContext* context, const TextR unPaintInfo& runInfo, const AtomicString& mark, const FloatPoint& point) const |
| 244 { | 246 { |
| 245 GlyphBuffer glyphBuffer; | 247 GlyphBuffer glyphBuffer; |
| 246 | 248 |
| 247 float initialAdvance = getGlyphsAndAdvancesForComplexText(runInfo, glyphBuff er, ForTextEmphasis); | 249 float initialAdvance = getGlyphsAndAdvancesForComplexText(runInfo, glyphBuff er, ForTextEmphasis); |
| 248 | 250 |
| 249 if (glyphBuffer.isEmpty()) | 251 if (glyphBuffer.isEmpty()) |
| 250 return; | 252 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 return shaper.selectionRect(point, height, from, to); | 297 return shaper.selectionRect(point, height, from, to); |
| 296 } | 298 } |
| 297 | 299 |
| 298 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia lAdvance, | 300 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia lAdvance, |
| 299 const FloatRect& bounds, float& advance, bool couldUseLCD) const | 301 const FloatRect& bounds, float& advance, bool couldUseLCD) const |
| 300 { | 302 { |
| 301 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); | 303 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); |
| 302 | 304 |
| 303 // FIXME: Except for setupPaint, this is not specific to FontHarfBuzz. | 305 // FIXME: Except for setupPaint, this is not specific to FontHarfBuzz. |
| 304 // FIXME: Also implement the more general full-positioning path. | 306 // FIXME: Also implement the more general full-positioning path. |
| 305 ASSERT(!glyphBuffer.hasVerticalAdvances()); | |
| 306 | 307 |
| 307 SkTextBlobBuilder builder; | 308 SkTextBlobBuilder builder; |
| 308 SkScalar x = SkFloatToScalar(initialAdvance); | 309 SkScalar x = SkFloatToScalar(initialAdvance); |
| 309 SkRect skBounds = bounds; | 310 SkRect skBounds = bounds; |
| 310 | 311 |
| 311 unsigned i = 0; | 312 unsigned i = 0; |
| 312 while (i < glyphBuffer.size()) { | 313 while (i < glyphBuffer.size()) { |
| 313 const SimpleFontData* fontData = glyphBuffer.fontDataAt(i); | 314 const SimpleFontData* fontData = glyphBuffer.fontDataAt(i); |
| 314 | 315 |
| 315 // FIXME: Handle vertical text. | 316 // FIXME: Handle vertical text. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 333 unsigned start = i++; | 334 unsigned start = i++; |
| 334 while (i < glyphBuffer.size() && glyphBuffer.fontDataAt(i) == fontData) | 335 while (i < glyphBuffer.size() && glyphBuffer.fontDataAt(i) == fontData) |
| 335 i++; | 336 i++; |
| 336 unsigned count = i - start; | 337 unsigned count = i - start; |
| 337 | 338 |
| 338 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPosH(paint, count, 0, &skBounds); | 339 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPosH(paint, count, 0, &skBounds); |
| 339 | 340 |
| 340 const uint16_t* glyphs = glyphBuffer.glyphs(start); | 341 const uint16_t* glyphs = glyphBuffer.glyphs(start); |
| 341 std::copy(glyphs, glyphs + count, buffer.glyphs); | 342 std::copy(glyphs, glyphs + count, buffer.glyphs); |
| 342 | 343 |
| 343 const FloatSize* advances = glyphBuffer.advances(start); | 344 const FloatSize* offsets = glyphBuffer.offsets(start); |
|
f(malita)
2014/09/25 16:42:05
I think we still want advances here. We only suppo
eae
2014/09/26 05:26:51
Right, thanks!
| |
| 344 for (unsigned j = 0; j < count; j++) { | 345 for (unsigned j = 0; j < count; j++) { |
| 345 buffer.pos[j] = x; | 346 buffer.pos[j] = x; |
| 346 x += SkFloatToScalar(advances[j].width()); | 347 x += SkFloatToScalar(offsets[j].width()); |
| 347 } | 348 } |
| 348 } | 349 } |
| 349 | 350 |
| 350 advance = x; | 351 advance = x; |
| 351 return adoptRef(builder.build()); | 352 return adoptRef(builder.build()); |
| 352 } | 353 } |
| 353 | 354 |
| 354 } // namespace blink | 355 } // namespace blink |
| OLD | NEW |