Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions
SkShaper_primitive.cpp File Reference
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTo.h"
#include "modules/skshaper/include/SkShaper.h"
#include "src/base/SkUTF.h"
#include "include/core/SkFontMgr.h"
#include <cstdint>
#include <cstring>
#include <memory>

Go to the source code of this file.

Classes

class  SkShaperPrimitive
 

Namespaces

namespace  SkShapers
 
namespace  SkShapers::Primitive
 

Functions

static bool is_breaking_whitespace (SkUnichar c)
 
static size_t linebreak (const char text[], const char stop[], const SkFont &font, SkScalar width, SkScalar *advance, size_t *trailing)
 
SKSHAPER_API std::unique_ptr< SkShaperSkShapers::Primitive::PrimitiveText ()
 

Function Documentation

◆ is_breaking_whitespace()

static bool is_breaking_whitespace ( SkUnichar  c)
inlinestatic

Definition at line 54 of file SkShaper_primitive.cpp.

54 {
55 switch (c) {
56 case 0x0020: // SPACE
57 //case 0x00A0: // NO-BREAK SPACE
58 case 0x1680: // OGHAM SPACE MARK
59 case 0x180E: // MONGOLIAN VOWEL SEPARATOR
60 case 0x2000: // EN QUAD
61 case 0x2001: // EM QUAD
62 case 0x2002: // EN SPACE (nut)
63 case 0x2003: // EM SPACE (mutton)
64 case 0x2004: // THREE-PER-EM SPACE (thick space)
65 case 0x2005: // FOUR-PER-EM SPACE (mid space)
66 case 0x2006: // SIX-PER-EM SPACE
67 case 0x2007: // FIGURE SPACE
68 case 0x2008: // PUNCTUATION SPACE
69 case 0x2009: // THIN SPACE
70 case 0x200A: // HAIR SPACE
71 case 0x200B: // ZERO WIDTH SPACE
72 case 0x202F: // NARROW NO-BREAK SPACE
73 case 0x205F: // MEDIUM MATHEMATICAL SPACE
74 case 0x3000: // IDEOGRAPHIC SPACE
75 //case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
76 return true;
77 default:
78 return false;
79 }
80}

◆ linebreak()

static size_t linebreak ( const char  text[],
const char  stop[],
const SkFont font,
SkScalar  width,
SkScalar advance,
size_t *  trailing 
)
static

Definition at line 82 of file SkShaper_primitive.cpp.

86{
87 SkScalar accumulatedWidth = 0;
88 int glyphIndex = 0;
89 const char* start = text;
90 const char* wordStart = text;
91 bool prevWS = true;
92 *trailing = 0;
93
94 while (text < stop) {
95 const char* prevText = text;
96 SkUnichar uni = SkUTF::NextUTF8(&text, stop);
97 accumulatedWidth += advance[glyphIndex++];
98 bool currWS = is_breaking_whitespace(uni);
99
100 if (!currWS && prevWS) {
101 wordStart = prevText;
102 }
103 prevWS = currWS;
104
105 if (width < accumulatedWidth) {
106 bool consumeWhitespace = false;
107 if (currWS) {
108 // previous fit, put this and following whitespace in trailing
109 if (prevText == start) {
110 // don't put this in trailing if it's the first thing
111 prevText = text;
112 }
113 consumeWhitespace = true;
114 } else if (wordStart != start) {
115 // backup to the last whitespace that fit
116 text = wordStart;
117 } else if (prevText > start) {
118 // backup to just before the glyph that didn't fit
119 text = prevText;
120 } else {
121 // let it overflow, put any following whitespace in trailing
122 prevText = text;
123 consumeWhitespace = true;
124 }
125 if (consumeWhitespace) {
126 const char* next = text;
127 while (next < stop && is_breaking_whitespace(SkUTF::NextUTF8(&next, stop))) {
128 text = next;
129 }
130 if (trailing) {
131 *trailing = text - prevText;
132 }
133 }
134 break;
135 }
136 }
137
138 return text - start;
139}
static float next(float f)
static bool is_breaking_whitespace(SkUnichar c)
int32_t SkUnichar
Definition: SkTypes.h:175
float SkScalar
Definition: extension.cpp:12
std::u16string text
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
Definition: SkUTF.cpp:118
int32_t width