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/SkTypeface.h"
35#include "include/effects/SkGradientShader.h"
36#include "modules/skparagraph/include/DartTypes.h"
37#include "modules/skparagraph/include/FontCollection.h"
38#include "modules/skparagraph/include/Paragraph.h"
39#include "modules/skparagraph/include/ParagraphBuilder.h"
40#include "modules/skparagraph/include/ParagraphStyle.h"
41#include "modules/skunicode/include/SkUnicode_icu.h"
43#if defined OS_MAC || defined OS_IOS
44 #include "include/ports/SkFontMgr_mac_ct.h"
48 #include "include/ports/SkTypeface_win.h"
49 #pragma comment(lib, "skparagraph.lib")
53BEGIN_IGRAPHICS_NAMESPACE
55using namespace skia::textlayout;
57static sk_sp<SkFontMgr> fontmgr_factory() {
58#if defined OS_MAC || OS_IOS
59 return SkFontMgr_New_CoreText(
nullptr);
61 return SkFontMgr_New_DirectWrite();
63 #error "Not supported"
67bool g_factory_called =
false;
69sk_sp<SkFontMgr> SkFontMgr_RefDefault() {
70 static std::once_flag flag;
71 static sk_sp<SkFontMgr> mgr;
72 std::call_once(flag, [] {
73 mgr = fontmgr_factory();
74 g_factory_called =
true;
93 DoDrawContent(canvas);
204 void DoDrawContent(SkCanvas* canvas)
206 auto fontCollection = sk_make_sp<skia::textlayout::FontCollection>();
207 fontCollection->setDefaultFontManager(SkFontMgr_RefDefault());
209 canvas->clear(SK_ColorWHITE);
212 paint.setAntiAlias(
true);
213 paint.setColor(SK_ColorBLACK);
215 skia::textlayout::TextStyle style;
216 style.setForegroundColor(paint);
217 style.setFontFamilies({SkString(
"sans-serif")});
218 style.setFontSize(30);
219 skia::textlayout::ParagraphStyle paraStyle;
220 paraStyle.setTextStyle(style);
221 paraStyle.setTextAlign(skia::textlayout::TextAlign::kRight);
223 sk_sp<SkUnicode> unicode = SkUnicodes::ICU::Make();
226 if (unicode ==
nullptr)
228 const char* errorText =
"Failed to create SkUnicode - could not find icudtl.dat next to DLL/EXE";
229 DBGMSG(
"%s\n", errorText);
235 using skia::textlayout::ParagraphBuilder;
236 std::unique_ptr<ParagraphBuilder> builder =
237 ParagraphBuilder::make(paraStyle, fontCollection, unicode);
238 builder->addText(
" Furthermore, العربية نص جميل. द क्विक ब्राउन फ़ॉक्स jumps over the lazy 🐕.");
239 auto paragraph = builder->Build();
240 paragraph->layout(mRECT.
W() - 20);
241 paragraph->paint(canvas, 10, 10);
246END_IGRAPHICS_NAMESPACE
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
The lowest level base class of an IGraphics context.
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
A control that demonstrates how to draw rich text using SkParagraph.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Used to manage a rectangular area, independent of draw class/platform.