13 #ifndef IGRAPHICS_SKIA 14 #error This IControl only works with the Skia graphics backend 23 #include "IGraphicsSkia.h" 24 #include "include/core/SkCanvas.h" 25 #include "include/core/SkColorFilter.h" 26 #include "include/core/SkColorPriv.h" 27 #include "include/core/SkFontMgr.h" 28 #include "include/core/SkGraphics.h" 29 #include "include/core/SkPath.h" 30 #include "include/core/SkRegion.h" 31 #include "include/core/SkShader.h" 32 #include "include/core/SkStream.h" 33 #include "include/core/SkTextBlob.h" 34 #include "include/core/SkTime.h" 35 #include "include/core/SkTypeface.h" 36 #include "include/effects/SkGradientShader.h" 37 #include "include/utils/SkRandom.h" 38 #include "modules/skparagraph/include/Paragraph.h" 39 #include "modules/skparagraph/include/TypefaceFontProvider.h" 40 #include "modules/skparagraph/src/ParagraphBuilderImpl.h" 41 #include "modules/skparagraph/src/ParagraphImpl.h" 42 #include "modules/skparagraph/src/TextLine.h" 43 #include "modules/skparagraph/utils/TestFontCollection.h" 46 #pragma comment(lib, "skparagraph.lib") 47 #pragma comment(lib, "skshaper.lib") 51 BEGIN_IGRAPHICS_NAMESPACE
70 DoDrawContent(canvas);
73 void DoDrawContent(SkCanvas* canvas)
79 std::tuple<std::string, bool, bool, int, SkColor, SkColor, bool, TextDecorationStyle>>
80 gParagraph = { {
"monospace",
true,
false, 14, SK_ColorWHITE, SK_ColorRED,
true,
81 TextDecorationStyle::kDashed},
82 {
"Assyrian",
false,
false, 20, SK_ColorWHITE, SK_ColorBLUE,
false,
83 TextDecorationStyle::kDotted},
84 {
"serif",
true,
true, 10, SK_ColorWHITE, SK_ColorRED,
true,
85 TextDecorationStyle::kDouble},
86 {
"Arial",
false,
true, 16, SK_ColorGRAY, SK_ColorGREEN,
true,
87 TextDecorationStyle::kSolid},
88 {
"sans-serif",
false,
false, 8, SK_ColorWHITE, SK_ColorRED,
false,
89 TextDecorationStyle::kWavy} };
90 SkAutoCanvasRestore acr(canvas,
true);
93 canvas->drawColor(SK_ColorWHITE);
98 paint.setAntiAlias(
true);
99 paint.setColor(SK_ColorWHITE);
102 blue.setColor(SK_ColorBLUE);
104 TextStyle defaultStyle;
105 defaultStyle.setBackgroundColor(blue);
106 defaultStyle.setForegroundColor(paint);
107 ParagraphStyle paraStyle;
109 auto fontCollection = sk_make_sp<FontCollection>();
110 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
111 for (
auto i = 1; i < 5; ++i) {
112 defaultStyle.setFontSize(24 * i);
113 paraStyle.setTextStyle(defaultStyle);
114 ParagraphBuilderImpl builder(paraStyle, fontCollection);
115 std::string name =
"Paragraph: " + std::to_string(24 * i);
116 builder.addText(name.c_str(), name.length());
117 for (
auto para : gParagraph) {
119 style.setFontFamilies({ SkString(std::get<0>(para).c_str()) });
120 SkFontStyle fontStyle(std::get<1>(para) ? SkFontStyle::Weight::kBold_Weight
121 : SkFontStyle::Weight::kNormal_Weight,
122 SkFontStyle::Width::kNormal_Width,
123 std::get<2>(para) ? SkFontStyle::Slant::kItalic_Slant
124 : SkFontStyle::Slant::kUpright_Slant);
125 style.setFontStyle(fontStyle);
126 style.setFontSize(std::get<3>(para) * i);
128 background.setColor(std::get<4>(para));
129 style.setBackgroundColor(background);
131 foreground.setColor(std::get<5>(para));
132 foreground.setAntiAlias(
true);
133 style.setForegroundColor(foreground);
134 if (std::get<6>(para)) {
135 style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(5, 5), 2));
138 auto decoration = (i % 4);
139 if (decoration == 3) {
143 bool test = (TextDecoration)decoration != TextDecoration::kNoDecoration;
144 std::string deco = std::to_string((
int)decoration);
146 style.setDecoration((TextDecoration)decoration);
147 style.setDecorationStyle(std::get<7>(para));
148 style.setDecorationColor(std::get<5>(para));
150 builder.pushStyle(style);
151 std::string name =
" " + std::get<0>(para) +
" " +
152 (std::get<1>(para) ?
", bold" :
"") +
153 (std::get<2>(para) ?
", italic" :
"") +
" " +
154 std::to_string(std::get<3>(para) * i) +
155 (std::get<4>(para) != SK_ColorRED ?
", background" :
"") +
156 (std::get<5>(para) != SK_ColorWHITE ?
", foreground" :
"") +
157 (std::get<6>(para) ?
", shadow" :
"") +
158 (test ?
", decorations " + deco :
"") +
";";
159 builder.addText(name.c_str(), name.length());
163 auto paragraph = builder.Build();
164 paragraph->layout(w - margin * 2);
165 paragraph->paint(canvas, mRECT.L + margin, mRECT.T + margin);
167 canvas->translate(0, paragraph->getHeight());
198 END_IGRAPHICS_NAMESPACE
The lowest level base class of an IGraphics control.
Used to manage a rectangular area, independent of draw class/platform.
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics context.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
void Draw(IGraphics &g) override
Draw the control to the graphics context.
A control that demonstrates how to draw rich text using SkParagraph.