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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp

Issue 2336693002: Rendering text to a canvas in a frame-less document. (Closed)
Patch Set: Created 4 years, 3 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) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return state().hasFilter(canvas(), canvas()->size(), this); 367 return state().hasFilter(canvas(), canvas()->size(), this);
368 } 368 }
369 369
370 SkImageFilter* CanvasRenderingContext2D::stateGetFilter() 370 SkImageFilter* CanvasRenderingContext2D::stateGetFilter()
371 { 371 {
372 return state().getFilter(canvas(), canvas()->size(), this); 372 return state().getFilter(canvas(), canvas()->size(), this);
373 } 373 }
374 374
375 void CanvasRenderingContext2D::snapshotStateForFilter() 375 void CanvasRenderingContext2D::snapshotStateForFilter()
376 { 376 {
377 // The style resolution required for fonts is not available in frame-less do cuments.
378 if (!canvas()->document().frame())
379 return;
380
381 modifiableState().setFontForFilter(accessFont()); 377 modifiableState().setFontForFilter(accessFont());
382 } 378 }
383 379
384 SkCanvas* CanvasRenderingContext2D::drawingCanvas() const 380 SkCanvas* CanvasRenderingContext2D::drawingCanvas() const
385 { 381 {
386 if (isContextLost()) 382 if (isContextLost())
387 return nullptr; 383 return nullptr;
388 return canvas()->drawingCanvas(); 384 return canvas()->drawingCanvas();
389 } 385 }
390 386
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 432
437 serializedFont.append(' '); 433 serializedFont.append(' ');
438 serializedFont.append(family); 434 serializedFont.append(family);
439 } 435 }
440 436
441 return serializedFont.toString(); 437 return serializedFont.toString();
442 } 438 }
443 439
444 void CanvasRenderingContext2D::setFont(const String& newFont) 440 void CanvasRenderingContext2D::setFont(const String& newFont)
445 { 441 {
446 // The style resolution required for rendering text is not available in fram e-less documents.
447 if (!canvas()->document().frame())
448 return;
449
450 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); 442 canvas()->document().updateStyleAndLayoutTreeForNode(canvas());
451 443
452 // The following early exit is dependent on the cache not being empty 444 // The following early exit is dependent on the cache not being empty
453 // because an empty cache may indicate that a style change has occured 445 // because an empty cache may indicate that a style change has occured
454 // which would require that the font be re-resolved. This check has to 446 // which would require that the font be re-resolved. This check has to
455 // come after the layout tree update to flush pending style changes. 447 // come after the layout tree update to flush pending style changes.
456 if (newFont == state().unparsedFont() && state().hasRealizedFont() && m_font sResolvedUsingCurrentStyle.size() > 0) 448 if (newFont == state().unparsedFont() && state().hasRealizedFont() && m_font sResolvedUsingCurrentStyle.size() > 0)
457 return; 449 return;
458 450
459 CanvasFontCache* canvasFontCache = canvas()->document().canvasFontCache(); 451 CanvasFontCache* canvasFontCache = canvas()->document().canvasFontCache();
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 void CanvasRenderingContext2D::strokeText(const String& text, double x, double y , double maxWidth) 712 void CanvasRenderingContext2D::strokeText(const String& text, double x, double y , double maxWidth)
721 { 713 {
722 trackDrawCall(StrokeText); 714 trackDrawCall(StrokeText);
723 drawTextInternal(text, x, y, CanvasRenderingContext2DState::StrokePaintType, &maxWidth); 715 drawTextInternal(text, x, y, CanvasRenderingContext2DState::StrokePaintType, &maxWidth);
724 } 716 }
725 717
726 TextMetrics* CanvasRenderingContext2D::measureText(const String& text) 718 TextMetrics* CanvasRenderingContext2D::measureText(const String& text)
727 { 719 {
728 TextMetrics* metrics = TextMetrics::create(); 720 TextMetrics* metrics = TextMetrics::create();
729 721
730 // The style resolution required for rendering text is not available in fram e-less documents.
731 if (!canvas()->document().frame())
732 return metrics;
733
734 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); 722 canvas()->document().updateStyleAndLayoutTreeForNode(canvas());
735 const Font& font = accessFont(); 723 const Font& font = accessFont();
736 724
737 TextDirection direction; 725 TextDirection direction;
738 if (state().getDirection() == CanvasRenderingContext2DState::DirectionInheri t) 726 if (state().getDirection() == CanvasRenderingContext2DState::DirectionInheri t)
739 direction = determineDirectionality(text); 727 direction = determineDirectionality(text);
740 else 728 else
741 direction = toTextDirection(state().getDirection(), canvas()); 729 direction = toTextDirection(state().getDirection(), canvas());
742 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion | TextRun::Forbi dLeadingExpansion, direction, false); 730 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion | TextRun::Forbi dLeadingExpansion, direction, false);
743 textRun.setNormalizeSpace(true); 731 textRun.setNormalizeSpace(true);
(...skipping 21 matching lines...) Expand all
765 metrics->setEmHeightDescent(0); 753 metrics->setEmHeightDescent(0);
766 754
767 metrics->setHangingBaseline(0.8f * ascent - baselineY); 755 metrics->setHangingBaseline(0.8f * ascent - baselineY);
768 metrics->setAlphabeticBaseline(-baselineY); 756 metrics->setAlphabeticBaseline(-baselineY);
769 metrics->setIdeographicBaseline(-descent - baselineY); 757 metrics->setIdeographicBaseline(-descent - baselineY);
770 return metrics; 758 return metrics;
771 } 759 }
772 760
773 void CanvasRenderingContext2D::drawTextInternal(const String& text, double x, do uble y, CanvasRenderingContext2DState::PaintType paintType, double* maxWidth) 761 void CanvasRenderingContext2D::drawTextInternal(const String& text, double x, do uble y, CanvasRenderingContext2DState::PaintType paintType, double* maxWidth)
774 { 762 {
775 // The style resolution required for rendering text is not available in fram e-less documents.
776 if (!canvas()->document().frame())
777 return;
778
779 // accessFont needs the style to be up to date, but updating style can cause script to run, 763 // accessFont needs the style to be up to date, but updating style can cause script to run,
780 // (e.g. due to autofocus) which can free the canvas (set size to 0, for exa mple), so update 764 // (e.g. due to autofocus) which can free the canvas (set size to 0, for exa mple), so update
781 // style before grabbing the drawingCanvas. 765 // style before grabbing the drawingCanvas.
782 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); 766 canvas()->document().updateStyleAndLayoutTreeForNode(canvas());
783 767
784 SkCanvas* c = drawingCanvas(); 768 SkCanvas* c = drawingCanvas();
785 if (!c) 769 if (!c)
786 return; 770 return;
787 771
788 if (!std::isfinite(x) || !std::isfinite(y)) 772 if (!std::isfinite(x) || !std::isfinite(y))
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 return true; 1081 return true;
1098 } 1082 }
1099 1083
1100 void CanvasRenderingContext2D::resetUsageTracking() 1084 void CanvasRenderingContext2D::resetUsageTracking()
1101 { 1085 {
1102 UsageCounters newCounters; 1086 UsageCounters newCounters;
1103 m_usageCounters = newCounters; 1087 m_usageCounters = newCounters;
1104 } 1088 }
1105 1089
1106 } // namespace blink 1090 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698