Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
userfont.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/utils/SkCustomTypeface.h"
#include "src/core/SkFontPriv.h"
#include "tools/Resources.h"
#include "tools/fonts/FontToolUtils.h"
#include "include/core/SkTextBlob.h"

Go to the source code of this file.

Classes

class  UserFontGM
 

Functions

static sk_sp< SkDrawablemake_drawable (const SkPath &path)
 
static sk_sp< SkTypefacemake_tf ()
 
static sk_sp< SkTypefaceround_trip (sk_sp< SkTypeface > tf)
 

Function Documentation

◆ make_drawable()

static sk_sp< SkDrawable > make_drawable ( const SkPath path)
static

Definition at line 23 of file userfont.cpp.

23 {
24 const auto bounds = path.computeTightBounds();
25
26 SkPictureRecorder recorder;
27 auto* canvas = recorder.beginRecording(bounds);
28
30 paint.setColor(0xff008000);
31 paint.setAntiAlias(true);
32
33 canvas->drawPath(path, paint);
34
35 return recorder.finishRecordingAsDrawable();
36}
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkDrawable > finishRecordingAsDrawable()
const Paint & paint
Optional< SkRect > bounds
Definition SkRecords.h:189
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57

◆ make_tf()

static sk_sp< SkTypeface > make_tf ( )
static

Definition at line 38 of file userfont.cpp.

38 {
41 SkASSERT(font.getTypeface());
42 const float upem = font.getTypeface()->getUnitsPerEm();
43
44 // request a big size, to improve precision at the fontscaler level
45 font.setSize(upem);
46 font.setHinting(SkFontHinting::kNone);
47
48 // so we can scale our paths back down to 1-point
49 const SkMatrix scale = SkMatrix::Scale(1.0f/upem, 1.0f/upem);
50
51 {
52 SkFontMetrics metrics;
53 font.getMetrics(&metrics);
54 builder.setMetrics(metrics, 1.0f/upem);
55 }
56 builder.setFontStyle(font.getTypeface()->fontStyle());
57
58 // Steal the first 128 chars from the default font
59 for (SkGlyphID index = 0; index <= 127; ++index) {
60 SkGlyphID glyph = font.unicharToGlyph(index);
61
63 font.getWidths(&glyph, 1, &width);
65 font.getPath(glyph, &path);
66 path.transform(scale);
67
68 // we use the charcode to be our glyph index, since we have no cmap table
69 if (index % 2) {
70 builder.setGlyph(index, width/upem, make_drawable(path), path.computeTightBounds());
71 } else {
72 builder.setGlyph(index, width/upem, path);
73 }
74 }
75
76 return builder.detach();
77}
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kNone
glyph outlines unchanged
uint16_t SkGlyphID
Definition SkTypes.h:179
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
float SkScalar
Definition extension.cpp:12
SkFont DefaultFont()
font
Font Metadata and Metrics.
int32_t width
const Scalar scale
static sk_sp< SkDrawable > make_drawable(const SkPath &path)
Definition userfont.cpp:23

◆ round_trip()

static sk_sp< SkTypeface > round_trip ( sk_sp< SkTypeface tf)
static

Definition at line 81 of file userfont.cpp.

81 {
82 auto data = tf->serialize();
83 SkMemoryStream stream(data->data(), data->size());
84 sk_sp<SkTypeface> face = SkTypeface::MakeDeserialize(&stream, nullptr);
85 SkASSERT(face);
86 return face;
87}
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
static sk_sp< SkTypeface > MakeDeserialize(SkStream *, sk_sp< SkFontMgr > lastResortMgr)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41