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

Side by Side Diff: Source/core/platform/graphics/FontFastPath.cpp

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed build on win and mac Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/platform/graphics/Font.cpp ('k') | Source/core/platform/graphics/GraphicsContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Holger Hans Peter Freyther 3 * Copyright (C) 2008 Holger Hans Peter Freyther
4 * Copyright (C) 2009 Torch Mobile, Inc. 4 * Copyright (C) 2009 Torch Mobile, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 initialAdvance = finalRoundingWidth + it.m_runWidthSoFar - afterWidth; 419 initialAdvance = finalRoundingWidth + it.m_runWidthSoFar - afterWidth;
420 } else 420 } else
421 initialAdvance = beforeWidth; 421 initialAdvance = beforeWidth;
422 422
423 if (run.rtl()) 423 if (run.rtl())
424 glyphBuffer.reverse(0, glyphBuffer.size()); 424 glyphBuffer.reverse(0, glyphBuffer.size());
425 425
426 return initialAdvance; 426 return initialAdvance;
427 } 427 }
428 428
429 void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const Fl oatPoint& point, int from, int to) const 429 void Font::drawSimpleText(GraphicsContext* context, const TextRunPaintInfo& runI nfo, const FloatPoint& point) const
430 { 430 {
431 // This glyph buffer holds our glyphs+advances+font data for each glyph. 431 // This glyph buffer holds our glyphs+advances+font data for each glyph.
432 GlyphBuffer glyphBuffer; 432 GlyphBuffer glyphBuffer;
433 433
434 float startX = point.x() + getGlyphsAndAdvancesForSimpleText(run, from, to, glyphBuffer); 434 float startX = point.x() + getGlyphsAndAdvancesForSimpleText(runInfo.run, ru nInfo.from, runInfo.to, glyphBuffer);
435 435
436 if (glyphBuffer.isEmpty()) 436 if (glyphBuffer.isEmpty())
437 return; 437 return;
438 438
439 FloatPoint startPoint(startX, point.y()); 439 FloatPoint startPoint(startX, point.y());
440 drawGlyphBuffer(context, run, glyphBuffer, startPoint); 440 drawGlyphBuffer(context, runInfo, glyphBuffer, startPoint);
441 } 441 }
442 442
443 void Font::drawEmphasisMarksForSimpleText(GraphicsContext* context, const TextRu n& run, const AtomicString& mark, const FloatPoint& point, int from, int to) con st 443 void Font::drawEmphasisMarksForSimpleText(GraphicsContext* context, const TextRu nPaintInfo& runInfo, const AtomicString& mark, const FloatPoint& point) const
444 { 444 {
445 GlyphBuffer glyphBuffer; 445 GlyphBuffer glyphBuffer;
446 float initialAdvance = getGlyphsAndAdvancesForSimpleText(run, from, to, glyp hBuffer, ForTextEmphasis); 446 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo.run, runInf o.from, runInfo.to, glyphBuffer, ForTextEmphasis);
447 447
448 if (glyphBuffer.isEmpty()) 448 if (glyphBuffer.isEmpty())
449 return; 449 return;
450 450
451 drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + in itialAdvance, point.y())); 451 drawEmphasisMarks(context, runInfo, glyphBuffer, mark, FloatPoint(point.x() + initialAdvance, point.y()));
452 } 452 }
453 453
454 void Font::drawGlyphBuffer(GraphicsContext* context, const TextRun& run, const G lyphBuffer& glyphBuffer, const FloatPoint& point) const 454 void Font::drawGlyphBuffer(GraphicsContext* context, const TextRunPaintInfo& run Info, const GlyphBuffer& glyphBuffer, const FloatPoint& point) const
455 { 455 {
456 #if !ENABLE(SVG_FONTS)
457 UNUSED_PARAM(run);
458 #endif
459
460 // Draw each contiguous run of glyphs that use the same font data. 456 // Draw each contiguous run of glyphs that use the same font data.
461 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0); 457 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
462 FloatSize offset = glyphBuffer.offsetAt(0); 458 FloatSize offset = glyphBuffer.offsetAt(0);
463 FloatPoint startPoint(point); 459 FloatPoint startPoint(point);
464 float nextX = startPoint.x() + glyphBuffer.advanceAt(0); 460 float nextX = startPoint.x() + glyphBuffer.advanceAt(0);
465 int lastFrom = 0; 461 int lastFrom = 0;
466 int nextGlyph = 1; 462 int nextGlyph = 1;
467 #if ENABLE(SVG_FONTS) 463 #if ENABLE(SVG_FONTS)
468 TextRun::RenderingContext* renderingContext = run.renderingContext(); 464 TextRun::RenderingContext* renderingContext = runInfo.run.renderingContext() ;
469 #endif 465 #endif
470 while (nextGlyph < glyphBuffer.size()) { 466 while (nextGlyph < glyphBuffer.size()) {
471 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph); 467 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
472 FloatSize nextOffset = glyphBuffer.offsetAt(nextGlyph); 468 FloatSize nextOffset = glyphBuffer.offsetAt(nextGlyph);
473 469
474 if (nextFontData != fontData || nextOffset != offset) { 470 if (nextFontData != fontData || nextOffset != offset) {
475 #if ENABLE(SVG_FONTS) 471 #if ENABLE(SVG_FONTS)
476 if (renderingContext && fontData->isSVGFont()) 472 if (renderingContext && fontData->isSVGFont())
477 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuf fer, lastFrom, nextGlyph - lastFrom, startPoint); 473 renderingContext->drawSVGGlyphs(context, runInfo.run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
478 else 474 else
479 #endif 475 #endif
480 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint); 476 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, runInfo.bounds);
481 477
482 lastFrom = nextGlyph; 478 lastFrom = nextGlyph;
483 fontData = nextFontData; 479 fontData = nextFontData;
484 offset = nextOffset; 480 offset = nextOffset;
485 startPoint.setX(nextX); 481 startPoint.setX(nextX);
486 } 482 }
487 nextX += glyphBuffer.advanceAt(nextGlyph); 483 nextX += glyphBuffer.advanceAt(nextGlyph);
488 nextGlyph++; 484 nextGlyph++;
489 } 485 }
490 486
491 #if ENABLE(SVG_FONTS) 487 #if ENABLE(SVG_FONTS)
492 if (renderingContext && fontData->isSVGFont()) 488 if (renderingContext && fontData->isSVGFont())
493 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, las tFrom, nextGlyph - lastFrom, startPoint); 489 renderingContext->drawSVGGlyphs(context, runInfo.run, fontData, glyphBuf fer, lastFrom, nextGlyph - lastFrom, startPoint);
494 else 490 else
495 #endif 491 #endif
496 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFro m, startPoint); 492 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFro m, startPoint, runInfo.bounds);
497 } 493 }
498 494
499 inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph glyph) 495 inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph glyph)
500 { 496 {
501 if (fontData->platformData().orientation() == Horizontal) { 497 if (fontData->platformData().orientation() == Horizontal) {
502 FloatRect bounds = fontData->boundsForGlyph(glyph); 498 FloatRect bounds = fontData->boundsForGlyph(glyph);
503 return bounds.x() + bounds.width() / 2; 499 return bounds.x() + bounds.width() / 2;
504 } 500 }
505 // FIXME: Use glyph bounds once they make sense for vertical fonts. 501 // FIXME: Use glyph bounds once they make sense for vertical fonts.
506 return fontData->widthForGlyph(glyph) / 2; 502 return fontData->widthForGlyph(glyph) / 2;
507 } 503 }
508 504
509 inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, size_t i) 505 inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, size_t i)
510 { 506 {
511 return offsetToMiddleOfGlyph(glyphBuffer.fontDataAt(i), glyphBuffer.glyphAt( i)); 507 return offsetToMiddleOfGlyph(glyphBuffer.fontDataAt(i), glyphBuffer.glyphAt( i));
512 } 508 }
513 509
514 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) co nst 510 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& r unInfo, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoi nt& point) const
515 { 511 {
516 FontCachePurgePreventer purgePreventer; 512 FontCachePurgePreventer purgePreventer;
517 513
518 GlyphData markGlyphData; 514 GlyphData markGlyphData;
519 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) 515 if (!getEmphasisMarkGlyphData(mark, markGlyphData))
520 return; 516 return;
521 517
522 const SimpleFontData* markFontData = markGlyphData.fontData; 518 const SimpleFontData* markFontData = markGlyphData.fontData;
523 ASSERT(markFontData); 519 ASSERT(markFontData);
524 if (!markFontData) 520 if (!markFontData)
525 return; 521 return;
526 522
527 Glyph markGlyph = markGlyphData.glyph; 523 Glyph markGlyph = markGlyphData.glyph;
528 Glyph spaceGlyph = markFontData->spaceGlyph(); 524 Glyph spaceGlyph = markFontData->spaceGlyph();
529 525
530 float middleOfLastGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, 0); 526 float middleOfLastGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, 0);
531 FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph( markFontData, markGlyph), point.y()); 527 FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph( markFontData, markGlyph), point.y());
532 528
533 GlyphBuffer markBuffer; 529 GlyphBuffer markBuffer;
534 for (int i = 0; i + 1 < glyphBuffer.size(); ++i) { 530 for (int i = 0; i + 1 < glyphBuffer.size(); ++i) {
535 float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1); 531 float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1);
536 float advance = glyphBuffer.advanceAt(i) - middleOfLastGlyph + middleOfN extGlyph; 532 float advance = glyphBuffer.advanceAt(i) - middleOfLastGlyph + middleOfN extGlyph;
537 markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFont Data, advance); 533 markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFont Data, advance);
538 middleOfLastGlyph = middleOfNextGlyph; 534 middleOfLastGlyph = middleOfNextGlyph;
539 } 535 }
540 markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spa ceGlyph, markFontData, 0); 536 markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spa ceGlyph, markFontData, 0);
541 537
542 drawGlyphBuffer(context, run, markBuffer, startPoint); 538 drawGlyphBuffer(context, runInfo, markBuffer, startPoint);
543 } 539 }
544 540
545 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, GlyphOverflow* glyphOverflow) const 541 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
546 { 542 {
547 WidthIterator it(this, run, fallbackFonts, glyphOverflow); 543 WidthIterator it(this, run, fallbackFonts, glyphOverflow);
548 GlyphBuffer glyphBuffer; 544 GlyphBuffer glyphBuffer;
549 it.advance(run.length(), (typesettingFeatures() & (Kerning | Ligatures)) ? & glyphBuffer : 0); 545 it.advance(run.length(), (typesettingFeatures() & (Kerning | Ligatures)) ? & glyphBuffer : 0);
550 546
551 if (glyphOverflow) { 547 if (glyphOverflow) {
552 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent())); 548 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (delta <= 0) 610 if (delta <= 0)
615 break; 611 break;
616 } 612 }
617 } 613 }
618 } 614 }
619 615
620 return offset; 616 return offset;
621 } 617 }
622 618
623 } 619 }
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/Font.cpp ('k') | Source/core/platform/graphics/GraphicsContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698