Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkDWrite.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkDWrite_DEFINED
9#define SkDWrite_DEFINED
10
13
14#include <dwrite.h>
15#include <winsdkver.h>
16
17class SkString;
18
19////////////////////////////////////////////////////////////////////////////////
20// Factory
21
22IDWriteFactory* sk_get_dwrite_factory();
23
24////////////////////////////////////////////////////////////////////////////////
25// String conversion
26
27/** Prefer to use this type to prevent template proliferation. */
29
30/** Converts a utf8 string to a WCHAR string. */
31HRESULT sk_cstring_to_wchar(const char* skname, SkSMallocWCHAR* name);
32
33/** Converts a WCHAR string to a utf8 string.
34 * @param nameLen the number of WCHARs in the name.
35 */
36HRESULT sk_wchar_to_skstring(WCHAR* name, int nameLen, SkString* skname);
37
38////////////////////////////////////////////////////////////////////////////////
39// Locale
40
41HRESULT sk_get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* preferedLocale,
42 SkString* skname);
43
46
47////////////////////////////////////////////////////////////////////////////////
48// Table handling
49
51public:
52 AutoDWriteTable(IDWriteFontFace* fontFace, UINT32 beTag) : fExists(FALSE), fFontFace(fontFace) {
53 // Any errors are ignored, user must check fExists anyway.
54 fontFace->TryGetFontTable(beTag,
55 reinterpret_cast<const void **>(&fData), &fSize, &fLock, &fExists);
56 }
58 if (fExists) {
59 fFontFace->ReleaseFontTable(fLock);
60 }
61 }
62
63 const uint8_t* fData;
64 UINT32 fSize;
66private:
67 // Borrowed reference, the user must ensure the fontFace stays alive.
68 IDWriteFontFace* fFontFace;
69 void* fLock;
70};
71template<typename T> class AutoTDWriteTable : public AutoDWriteTable {
72public:
73 static const UINT32 tag = DWRITE_MAKE_OPENTYPE_TAG(T::TAG0, T::TAG1, T::TAG2, T::TAG3);
74 AutoTDWriteTable(IDWriteFontFace* fontFace) : AutoDWriteTable(fontFace, tag) { }
75
76 const T* get() const { return reinterpret_cast<const T*>(fData); }
77 const T* operator->() const { return reinterpret_cast<const T*>(fData); }
78};
79
80////////////////////////////////////////////////////////////////////////////////
81// Style conversion
82
84 explicit DWriteStyle(const SkFontStyle& pattern) {
85 fWeight = (DWRITE_FONT_WEIGHT)pattern.weight();
86 fWidth = (DWRITE_FONT_STRETCH)pattern.width();
87 switch (pattern.slant()) {
88 case SkFontStyle::kUpright_Slant: fSlant = DWRITE_FONT_STYLE_NORMAL ; break;
89 case SkFontStyle::kItalic_Slant: fSlant = DWRITE_FONT_STYLE_ITALIC ; break;
90 case SkFontStyle::kOblique_Slant: fSlant = DWRITE_FONT_STYLE_OBLIQUE; break;
91 default: SkASSERT(false); break;
92 }
93 }
94 DWRITE_FONT_WEIGHT fWeight;
95 DWRITE_FONT_STRETCH fWidth;
96 DWRITE_FONT_STYLE fSlant;
97};
98
99#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
HRESULT sk_wchar_to_skstring(WCHAR *name, int nameLen, SkString *skname)
HRESULT sk_get_locale_string(IDWriteLocalizedStrings *names, const WCHAR *preferedLocale, SkString *skname)
int(WINAPI * SkGetUserDefaultLocaleNameProc)(LPWSTR, int)
Definition SkDWrite.h:44
HRESULT sk_cstring_to_wchar(const char *skname, SkSMallocWCHAR *name)
HRESULT SkGetGetUserDefaultLocaleNameProc(SkGetUserDefaultLocaleNameProc *proc)
skia_private::AutoSTMalloc< 16, WCHAR > SkSMallocWCHAR
Definition SkDWrite.h:28
IDWriteFactory * sk_get_dwrite_factory()
Type::kYUV Type::kRGBA() int(0.7 *637)
AutoDWriteTable(IDWriteFontFace *fontFace, UINT32 beTag)
Definition SkDWrite.h:52
const uint8_t * fData
Definition SkDWrite.h:63
const T * operator->() const
Definition SkDWrite.h:77
const T * get() const
Definition SkDWrite.h:76
AutoTDWriteTable(IDWriteFontFace *fontFace)
Definition SkDWrite.h:74
static const UINT32 tag
Definition SkDWrite.h:73
Slant slant() const
Definition SkFontStyle.h:64
int width() const
Definition SkFontStyle.h:63
int weight() const
Definition SkFontStyle.h:62
const char * name
Definition fuchsia.cc:50
return FALSE
#define T
DWriteStyle(const SkFontStyle &pattern)
Definition SkDWrite.h:84
DWRITE_FONT_WEIGHT fWeight
Definition SkDWrite.h:94
DWRITE_FONT_STRETCH fWidth
Definition SkDWrite.h:95
DWRITE_FONT_STYLE fSlant
Definition SkDWrite.h:96
int BOOL
#define WINAPI