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

Side by Side Diff: Source/core/layout/LayoutBlockFlowLine.cpp

Issue 1179723002: Store glyph bounds in WordMeasurement to avoid slow path width calc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: For review Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ight reserved. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ight reserved.
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
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 15 matching lines...) Expand all
26 #include "core/layout/BidiRunForLine.h" 26 #include "core/layout/BidiRunForLine.h"
27 #include "core/layout/LayoutCounter.h" 27 #include "core/layout/LayoutCounter.h"
28 #include "core/layout/LayoutFlowThread.h" 28 #include "core/layout/LayoutFlowThread.h"
29 #include "core/layout/LayoutListMarker.h" 29 #include "core/layout/LayoutListMarker.h"
30 #include "core/layout/LayoutObject.h" 30 #include "core/layout/LayoutObject.h"
31 #include "core/layout/LayoutRubyRun.h" 31 #include "core/layout/LayoutRubyRun.h"
32 #include "core/layout/LayoutView.h" 32 #include "core/layout/LayoutView.h"
33 #include "core/layout/TextRunConstructor.h" 33 #include "core/layout/TextRunConstructor.h"
34 #include "core/layout/VerticalPositionCache.h" 34 #include "core/layout/VerticalPositionCache.h"
35 #include "core/layout/line/BreakingContextInlineHeaders.h" 35 #include "core/layout/line/BreakingContextInlineHeaders.h"
36 #include "core/layout/line/GlyphOverflow.h"
36 #include "core/layout/line/LayoutTextInfo.h" 37 #include "core/layout/line/LayoutTextInfo.h"
37 #include "core/layout/line/LineLayoutState.h" 38 #include "core/layout/line/LineLayoutState.h"
38 #include "core/layout/line/LineWidth.h" 39 #include "core/layout/line/LineWidth.h"
39 #include "core/layout/line/TrailingFloatsRootInlineBox.h" 40 #include "core/layout/line/TrailingFloatsRootInlineBox.h"
40 #include "core/layout/line/WordMeasurement.h" 41 #include "core/layout/line/WordMeasurement.h"
41 #include "core/layout/svg/line/SVGRootInlineBox.h" 42 #include "core/layout/svg/line/SVGRootInlineBox.h"
42 #include "platform/fonts/Character.h" 43 #include "platform/fonts/Character.h"
43 #include "platform/text/BidiResolver.h" 44 #include "platform/text/BidiResolver.h"
44 #include "wtf/RefCountedLeakCounter.h" 45 #include "wtf/RefCountedLeakCounter.h"
45 #include "wtf/StdLibExtras.h" 46 #include "wtf/StdLibExtras.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 setMarginStartForChild(*layoutRubyRun, -startOverhang); 365 setMarginStartForChild(*layoutRubyRun, -startOverhang);
365 setMarginEndForChild(*layoutRubyRun, -endOverhang); 366 setMarginEndForChild(*layoutRubyRun, -endOverhang);
366 } 367 }
367 368
368 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru n, LayoutText* layoutText, LayoutUnit xPos, const LineInfo& lineInfo, 369 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru n, LayoutText* layoutText, LayoutUnit xPos, const LineInfo& lineInfo,
369 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& ver ticalPositionCache, WordMeasurements& wordMeasurements) 370 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& ver ticalPositionCache, WordMeasurements& wordMeasurements)
370 { 371 {
371 HashSet<const SimpleFontData*> fallbackFonts; 372 HashSet<const SimpleFontData*> fallbackFonts;
372 GlyphOverflow glyphOverflow; 373 GlyphOverflow glyphOverflow;
373 374
375 const Font& font = layoutText->style(lineInfo.isFirstLine())->font();
374 // Always compute glyph overflow bounds if the block's line-box-contain valu e is "glyphs". 376 // Always compute glyph overflow bounds if the block's line-box-contain valu e is "glyphs".
375 if (lineBox->fitsToGlyphs()) 377 if (lineBox->fitsToGlyphs())
376 glyphOverflow.computeBounds = true; 378 glyphOverflow.computeBounds = true;
377 379
378 LayoutUnit hyphenWidth = 0; 380 LayoutUnit hyphenWidth = 0;
379 if (toInlineTextBox(run->m_box)->hasHyphen()) { 381 if (toInlineTextBox(run->m_box)->hasHyphen())
380 const Font& font = layoutText->style(lineInfo.isFirstLine())->font();
381 hyphenWidth = measureHyphenWidth(layoutText, font, run->direction()); 382 hyphenWidth = measureHyphenWidth(layoutText, font, run->direction());
383
Xianzhu 2015/06/11 18:22:48 Line 384 to line 432 below are original LayoutBloc
384 float measuredWidth = 0;
385 FloatRect glyphBounds;
386
387 bool kerningIsEnabled = font.fontDescription().typesettingFeatures() & Kerni ng;
388
389 #if OS(MACOSX)
390 // FIXME: Having any font feature settings enabled can lead to selection gap s on
391 // Chromium-mac. https://bugs.webkit.org/show_bug.cgi?id=113418
392 bool canUseSimpleFontCodePath = layoutText->canUseSimpleFontCodePath() && !f ont.fontDescription().featureSettings();
393 #else
394 bool canUseSimpleFontCodePath = layoutText->canUseSimpleFontCodePath();
395 #endif
396
397 if (canUseSimpleFontCodePath) {
Xianzhu 2015/06/11 18:22:47 We can use fast path when fitToGlyphs() because no
398 int lastEndOffset = run->m_start;
399 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOf fset < run->m_stop; ++i) {
400 const WordMeasurement& wordMeasurement = wordMeasurements[i];
401 if (wordMeasurement.width <=0 || wordMeasurement.startOffset == word Measurement.endOffset)
402 continue;
403 if (wordMeasurement.layoutText != layoutText || wordMeasurement.star tOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
404 continue;
405
406 lastEndOffset = wordMeasurement.endOffset;
407 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
408 int wordLength = lastEndOffset - wordMeasurement.startOffset;
409 measuredWidth += layoutText->width(wordMeasurement.startOffset, wordLength, xPos, run->direction(), lineInfo.isFirstLine());
410 if (i > 0 && wordLength == 1 && layoutText->characterAt(wordMeas urement.startOffset) == ' ')
411 measuredWidth += layoutText->style()->wordSpacing();
412 } else {
413 FloatRect wordGlyphBounds = wordMeasurement.glyphBounds;
414 wordGlyphBounds.move(measuredWidth, 0);
415 glyphBounds.unite(wordGlyphBounds);
Xianzhu 2015/06/11 18:22:48 Line 413-415 are added to accumulate work glyph bo
416 measuredWidth += wordMeasurement.width;
417 }
418 if (!wordMeasurement.fallbackFonts.isEmpty()) {
419 HashSet<const SimpleFontData*>::const_iterator end = wordMeasure ment.fallbackFonts.end();
420 for (HashSet<const SimpleFontData*>::const_iterator it = wordMea surement.fallbackFonts.begin(); it != end; ++it)
421 fallbackFonts.add(*it);
422 }
423 }
424 if (measuredWidth && lastEndOffset != run->m_stop) {
425 // If we don't have enough cached data, we'll measure the run again.
426 measuredWidth = 0;
427 fallbackFonts.clear();
428 }
382 } 429 }
383 430
384 float measuredWidth = layoutText->width(run->m_start, run->m_stop - run->m_s tart, xPos, run->direction(), lineInfo.isFirstLine(), &fallbackFonts, &glyphOver flow); 431 if (!measuredWidth)
432 measuredWidth = layoutText->width(run->m_start, run->m_stop - run->m_sta rt, xPos, run->direction(), lineInfo.isFirstLine(), &fallbackFonts, &glyphBounds );
433
434 glyphOverflow.setFromBounds(glyphBounds, font.fontMetrics().floatAscent(), f ont.fontMetrics().floatDescent(), measuredWidth);
385 435
386 run->m_box->setLogicalWidth(measuredWidth + hyphenWidth); 436 run->m_box->setLogicalWidth(measuredWidth + hyphenWidth);
387 if (!fallbackFonts.isEmpty()) { 437 if (!fallbackFonts.isEmpty()) {
388 ASSERT(run->m_box->isText()); 438 ASSERT(run->m_box->isText());
389 GlyphOverflowAndFallbackFontsMap::ValueType* it = textBoxDataMap.add(toI nlineTextBox(run->m_box), std::make_pair(Vector<const SimpleFontData*>(), GlyphO verflow())).storedValue; 439 GlyphOverflowAndFallbackFontsMap::ValueType* it = textBoxDataMap.add(toI nlineTextBox(run->m_box), std::make_pair(Vector<const SimpleFontData*>(), GlyphO verflow())).storedValue;
390 ASSERT(it->value.first.isEmpty()); 440 ASSERT(it->value.first.isEmpty());
391 copyToVector(fallbackFonts, it->value.first); 441 copyToVector(fallbackFonts, it->value.first);
392 run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline(); 442 run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
393 } 443 }
394 if (!glyphOverflow.isZero()) { 444 if (!glyphOverflow.isZero()) {
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 LayoutUnit logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false); 2042 LayoutUnit logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
1993 LayoutUnit availableLogicalWidth = logicalRightOffsetForLine(logicalHeight() , false) - logicalLeft; 2043 LayoutUnit availableLogicalWidth = logicalRightOffsetForLine(logicalHeight() , false) - logicalLeft;
1994 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWid th, availableLogicalWidth, 0); 2044 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWid th, availableLogicalWidth, 0);
1995 2045
1996 if (!style()->isLeftToRightDirection()) 2046 if (!style()->isLeftToRightDirection())
1997 return logicalWidth() - logicalLeft; 2047 return logicalWidth() - logicalLeft;
1998 return logicalLeft; 2048 return logicalLeft;
1999 } 2049 }
2000 2050
2001 } 2051 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698