diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/TextPainter.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/rendering/TextPainter.h')
-rw-r--r-- | Source/WebCore/rendering/TextPainter.h | 122 |
1 files changed, 78 insertions, 44 deletions
diff --git a/Source/WebCore/rendering/TextPainter.h b/Source/WebCore/rendering/TextPainter.h index cb2408c53..6ac040142 100644 --- a/Source/WebCore/rendering/TextPainter.h +++ b/Source/WebCore/rendering/TextPainter.h @@ -20,16 +20,20 @@ * */ -#ifndef TextPainter_h -#define TextPainter_h +#pragma once #include "AffineTransform.h" -#include "DashArray.h" -#include "RenderText.h" +#include "FloatRect.h" +#include "ShadowData.h" +#include "TextFlags.h" +#include "TextPaintStyle.h" +#include <wtf/text/AtomicString.h> namespace WebCore { +class FontCascade; class RenderCombineText; +class TextRun; struct TextPaintStyle; @@ -41,52 +45,82 @@ static inline AffineTransform rotation(const FloatRect& boxRect, RotationDirecti : AffineTransform(0, -1, 1, 0, boxRect.x() - boxRect.maxY(), boxRect.x() + boxRect.maxY()); } -struct SavedDrawingStateForMask { - SavedDrawingStateForMask(GraphicsContext* context, TextPaintStyle* textPaintStyle, TextPaintStyle* selectionPaintStyle, - const ShadowData* textShadow, const ShadowData* selectionShadow) - : m_context(context) - , m_textPaintStyle(textPaintStyle) - , m_selectionPaintStyle(selectionPaintStyle) - , m_textShadow(textShadow) - , m_selectionShadow(selectionShadow) - { - } - GraphicsContext* m_context; - TextPaintStyle* m_textPaintStyle; - TextPaintStyle* m_selectionPaintStyle; - const ShadowData* m_textShadow; - const ShadowData* m_selectionShadow; -}; - class TextPainter { public: - TextPainter(GraphicsContext&, bool paintSelectedTextOnly, bool paintSelectedTextSeparately, const Font&, - int startPositionInTextRun, int endPositionInTextBoxString, int length, const AtomicString& emphasisMark, RenderCombineText*, - TextRun&, FloatRect& boxRect, FloatPoint& textOrigin, int emphasisMarkOffset, const ShadowData* textShadow, const ShadowData* selectionShadow, - bool textBoxIsHorizontal, TextPaintStyle& nonSelectionPaintStyle, TextPaintStyle& selectionPaintStyle); + TextPainter(GraphicsContext&); - void paintText(); - void paintTextInContext(GraphicsContext&, float amountToIncreaseStrokeWidthBy); + void setTextPaintStyle(const TextPaintStyle& textPaintStyle) { m_textPaintStyle = textPaintStyle; } + void setSelectionPaintStyle(const TextPaintStyle& selectionPaintStyle) { m_selectionPaintStyle = selectionPaintStyle; } + void setIsHorizontal(bool isHorizontal) { m_textBoxIsHorizontal = isHorizontal; } + void setFont(const FontCascade& font) { m_font = &font; } + void addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText*); + void addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow); - DashArray dashesForIntersectionsWithRect(const FloatRect& lineExtents); + void paintText(const TextRun&, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, + unsigned selectionStart = 0, unsigned selectionEnd = 0, bool paintSelectedTextOnly = false, bool paintSelectedTextSeparately = false); private: - bool m_paintSelectedTextOnly; - bool m_paintSelectedTextSeparately; - const Font& m_font; - int m_startPositionInTextRun; - int m_endPositionInTextRun; - int m_length; - const AtomicString& m_emphasisMark; - RenderCombineText* m_combinedText; - TextRun& m_textRun; - FloatRect& m_boxRect; - FloatPoint& m_textOrigin; - int m_emphasisMarkOffset; - bool m_textBoxIsHorizontal; - SavedDrawingStateForMask m_savedDrawingStateForMask; + void drawTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset, + const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset); + void paintTextWithShadows(const ShadowData*, const FontCascade&, const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, + unsigned startOffset, unsigned endOffset, const AtomicString& emphasisMark, float emphasisMarkOffset, bool stroked); + void paintTextAndEmphasisMarksIfNeeded(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset, + const TextPaintStyle&, const ShadowData*); + + GraphicsContext& m_context; + const FontCascade* m_font { nullptr }; + TextPaintStyle m_textPaintStyle; + TextPaintStyle m_selectionPaintStyle; + const ShadowData* m_textShadow { nullptr }; + const ShadowData* m_selectionShadow { nullptr }; + AtomicString m_emphasisMark; + RenderCombineText* m_combinedText { nullptr }; + float m_emphasisMarkOffset { 0 }; + bool m_textBoxIsHorizontal { true }; }; -} // namespace WebCore +inline void TextPainter::addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText* combinedText) +{ + m_emphasisMark = emphasisMark; + m_emphasisMarkOffset = emphasisMarkOffset; + m_combinedText = combinedText; +} + +inline void TextPainter::addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow) +{ + m_textShadow = textShadow; + m_selectionShadow = selectionShadow; +} + +class ShadowApplier { +public: + ShadowApplier(GraphicsContext&, const ShadowData*, const FloatRect& textRect, bool lastShadowIterationShouldDrawText = true, bool opaque = false, FontOrientation = Horizontal); + FloatSize extraOffset() const { return m_extraOffset; } + bool nothingToDraw() const { return m_nothingToDraw; } + bool didSaveContext() const { return m_didSaveContext; } + ~ShadowApplier(); -#endif // TextPainter_h +private: + bool isLastShadowIteration(); + bool shadowIsCompletelyCoveredByText(bool textIsOpaque); + + FloatSize m_extraOffset; + GraphicsContext& m_context; + const ShadowData* m_shadow; + bool m_onlyDrawsShadow : 1; + bool m_avoidDrawingShadow : 1; + bool m_nothingToDraw : 1; + bool m_didSaveContext : 1; +}; + +inline bool ShadowApplier::isLastShadowIteration() +{ + return m_shadow && !m_shadow->next(); +} + +inline bool ShadowApplier::shadowIsCompletelyCoveredByText(bool textIsOpaque) +{ + return textIsOpaque && m_shadow && m_shadow->location() == IntPoint() && !m_shadow->radius(); +} + +} // namespace WebCore |