Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
SkShaper_primitive.cpp File Reference
#include "include/core/SkFont.h"
#include "include/core/SkFontMgr.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 <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)
 

Function Documentation

◆ is_breaking_whitespace()

static bool is_breaking_whitespace ( SkUnichar  c)
inlinestatic

Definition at line 52 of file SkShaper_primitive.cpp.

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

◆ 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 80 of file SkShaper_primitive.cpp.

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