[TextServer] Implement soft hyphen handling.
This commit is contained in:
parent
60b927b4cf
commit
ad017a20ea
|
@ -1924,6 +1924,9 @@
|
|||
<constant name="GRAPHEME_IS_EMBEDDED_OBJECT" value="4096" enum="GraphemeFlag" is_bitfield="true">
|
||||
Grapheme is an object replacement character for the embedded object.
|
||||
</constant>
|
||||
<constant name="GRAPHEME_IS_SOFT_HYPHEN" value="8192" enum="GraphemeFlag" is_bitfield="true">
|
||||
Grapheme is a soft hyphen.
|
||||
</constant>
|
||||
<constant name="HINTING_NONE" value="0" enum="Hinting">
|
||||
Disables font hinting (smoother but less crisp).
|
||||
</constant>
|
||||
|
|
|
@ -4588,6 +4588,12 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
|
|||
if ((sd_glyphs[j].start >= bidi_run_start) && (sd_glyphs[j].end <= bidi_run_end)) {
|
||||
// Copy glyphs.
|
||||
Glyph gl = sd_glyphs[j];
|
||||
if (gl.end == p_start + p_length && ((gl.flags & GRAPHEME_IS_SOFT_HYPHEN) == GRAPHEME_IS_SOFT_HYPHEN)) {
|
||||
uint32_t index = font_get_glyph_index(gl.font_rid, gl.font_size, 0x00ad, 0);
|
||||
float w = font_get_glyph_advance(gl.font_rid, gl.font_size, index)[(p_new_sd->orientation == ORIENTATION_HORIZONTAL) ? 0 : 1];
|
||||
gl.index = index;
|
||||
gl.advance = w;
|
||||
}
|
||||
Variant key;
|
||||
bool find_embedded = false;
|
||||
if (gl.count == 1) {
|
||||
|
@ -4708,22 +4714,22 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double
|
|||
|
||||
if (p_jst_flags.has_flag(JUSTIFICATION_TRIM_EDGE_SPACES)) {
|
||||
// Trim spaces.
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
justification_width -= sd->glyphs[start_pos].advance * sd->glyphs[start_pos].repeat;
|
||||
sd->glyphs.write[start_pos].advance = 0;
|
||||
start_pos += sd->glyphs[start_pos].count;
|
||||
}
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
justification_width -= sd->glyphs[end_pos].advance * sd->glyphs[end_pos].repeat;
|
||||
sd->glyphs.write[end_pos].advance = 0;
|
||||
end_pos -= sd->glyphs[end_pos].count;
|
||||
}
|
||||
} else {
|
||||
// Skip breaks, but do not reset size.
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
start_pos += sd->glyphs[start_pos].count;
|
||||
}
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
end_pos -= sd->glyphs[end_pos].count;
|
||||
}
|
||||
}
|
||||
|
@ -4739,7 +4745,7 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double
|
|||
elongation_count++;
|
||||
}
|
||||
}
|
||||
if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
if ((gl.flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN && (gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
space_count++;
|
||||
}
|
||||
}
|
||||
|
@ -4772,7 +4778,7 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double
|
|||
for (int i = start_pos; i <= end_pos; i++) {
|
||||
Glyph &gl = sd->glyphs.write[i];
|
||||
if (gl.count > 0) {
|
||||
if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
if ((gl.flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN && (gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
double old_adv = gl.advance;
|
||||
double new_advance;
|
||||
if ((gl.flags & GRAPHEME_IS_VIRTUAL) == GRAPHEME_IS_VIRTUAL) {
|
||||
|
@ -5420,6 +5426,9 @@ bool TextServerAdvanced::_shaped_text_update_breaks(const RID &p_shaped) {
|
|||
if (c == 0x0009 || c == 0x000b) {
|
||||
sd_glyphs_new[sd_shift + i].flags |= GRAPHEME_IS_TAB;
|
||||
}
|
||||
if (c == 0x00ad) {
|
||||
sd_glyphs_new[sd_shift + i].flags |= GRAPHEME_IS_SOFT_HYPHEN;
|
||||
}
|
||||
if (is_whitespace(c)) {
|
||||
sd_glyphs_new[sd_shift + i].flags |= GRAPHEME_IS_SPACE;
|
||||
}
|
||||
|
@ -5441,7 +5450,7 @@ bool TextServerAdvanced::_shaped_text_update_breaks(const RID &p_shaped) {
|
|||
if (sd->breaks.has(sd_glyphs[i].end)) {
|
||||
if (sd->breaks[sd_glyphs[i].end] && (is_linebreak(c))) {
|
||||
sd_glyphs_new[sd_shift + i].flags |= GRAPHEME_IS_BREAK_HARD;
|
||||
} else if (is_whitespace(c)) {
|
||||
} else if (is_whitespace(c) || c == 0x00ad) {
|
||||
sd_glyphs_new[sd_shift + i].flags |= GRAPHEME_IS_BREAK_SOFT;
|
||||
} else {
|
||||
int count = sd_glyphs[i].count;
|
||||
|
@ -5660,7 +5669,7 @@ bool TextServerAdvanced::_shaped_text_update_justification_ops(const RID &p_shap
|
|||
sd_glyphs[i].flags |= GRAPHEME_IS_ELONGATION;
|
||||
}
|
||||
if (sd->jstops.has(sd_glyphs[i].start)) {
|
||||
if (c == 0xfffc) {
|
||||
if (c == 0xfffc || c == 0x00ad) {
|
||||
continue;
|
||||
}
|
||||
if (sd->jstops[sd_glyphs[i].start]) {
|
||||
|
|
|
@ -3367,6 +3367,10 @@ RID TextServerFallback::_shaped_text_substr(const RID &p_shaped, int64_t p_start
|
|||
for (int i = 0; i < sd_size; i++) {
|
||||
if ((sd_glyphs[i].start >= new_sd->start) && (sd_glyphs[i].end <= new_sd->end)) {
|
||||
Glyph gl = sd_glyphs[i];
|
||||
if (gl.end == p_start + p_length && ((gl.flags & GRAPHEME_IS_SOFT_HYPHEN) == GRAPHEME_IS_SOFT_HYPHEN)) {
|
||||
gl.index = 0x00ad;
|
||||
gl.advance = font_get_glyph_advance(gl.font_rid, gl.font_size, 0x00ad).x;
|
||||
}
|
||||
Variant key;
|
||||
bool find_embedded = false;
|
||||
if (gl.count == 1) {
|
||||
|
@ -3480,22 +3484,22 @@ double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double
|
|||
|
||||
if (p_jst_flags.has_flag(JUSTIFICATION_TRIM_EDGE_SPACES)) {
|
||||
// Trim spaces.
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
justification_width -= sd->glyphs[start_pos].advance * sd->glyphs[start_pos].repeat;
|
||||
sd->glyphs.write[start_pos].advance = 0;
|
||||
start_pos += sd->glyphs[start_pos].count;
|
||||
}
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
justification_width -= sd->glyphs[end_pos].advance * sd->glyphs[end_pos].repeat;
|
||||
sd->glyphs.write[end_pos].advance = 0;
|
||||
end_pos -= sd->glyphs[end_pos].count;
|
||||
}
|
||||
} else {
|
||||
// Skip breaks, but do not reset size.
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
start_pos += sd->glyphs[start_pos].count;
|
||||
}
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD)) {
|
||||
while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
end_pos -= sd->glyphs[end_pos].count;
|
||||
}
|
||||
}
|
||||
|
@ -3504,7 +3508,7 @@ double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double
|
|||
for (int i = start_pos; i <= end_pos; i++) {
|
||||
const Glyph &gl = sd->glyphs[i];
|
||||
if (gl.count > 0) {
|
||||
if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
if ((gl.flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN && (gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
space_count++;
|
||||
}
|
||||
}
|
||||
|
@ -3515,7 +3519,7 @@ double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double
|
|||
for (int i = start_pos; i <= end_pos; i++) {
|
||||
Glyph &gl = sd->glyphs.write[i];
|
||||
if (gl.count > 0) {
|
||||
if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
if ((gl.flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN && (gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE && (gl.flags & GRAPHEME_IS_PUNCTUATION) != GRAPHEME_IS_PUNCTUATION) {
|
||||
double old_adv = gl.advance;
|
||||
gl.advance = MAX(gl.advance + delta_width_per_space, Math::round(0.1 * gl.font_size));
|
||||
justification_width += (gl.advance - old_adv);
|
||||
|
@ -3641,6 +3645,9 @@ bool TextServerFallback::_shaped_text_update_breaks(const RID &p_shaped) {
|
|||
if (c == 0x0009 || c == 0x000b) {
|
||||
sd_glyphs[i].flags |= GRAPHEME_IS_TAB;
|
||||
}
|
||||
if (c == 0x00ad) {
|
||||
sd_glyphs[i].flags |= GRAPHEME_IS_SOFT_HYPHEN;
|
||||
}
|
||||
|
||||
i += (sd_glyphs[i].count - 1);
|
||||
}
|
||||
|
|
|
@ -572,6 +572,7 @@ void TextServer::_bind_methods() {
|
|||
BIND_BITFIELD_FLAG(GRAPHEME_IS_CONNECTED);
|
||||
BIND_BITFIELD_FLAG(GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL);
|
||||
BIND_BITFIELD_FLAG(GRAPHEME_IS_EMBEDDED_OBJECT);
|
||||
BIND_BITFIELD_FLAG(GRAPHEME_IS_SOFT_HYPHEN);
|
||||
|
||||
/* Hinting */
|
||||
BIND_ENUM_CONSTANT(HINTING_NONE);
|
||||
|
@ -733,6 +734,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped
|
|||
|
||||
ERR_FAIL_COND_V(p_width.is_empty(), lines);
|
||||
|
||||
TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped);
|
||||
const_cast<TextServer *>(this)->shaped_text_update_breaks(p_shaped);
|
||||
const Vector2i &range = shaped_text_get_range(p_shaped);
|
||||
|
||||
|
@ -758,10 +760,10 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped
|
|||
if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
|
||||
int start_pos = prev_safe_break;
|
||||
int end_pos = last_safe_break;
|
||||
while (trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while (trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
start_pos += l_gl[start_pos].count;
|
||||
}
|
||||
while ((start_pos < end_pos) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((l_gl[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
end_pos -= l_gl[end_pos].count;
|
||||
}
|
||||
if (last_end <= l_gl[start_pos].start) {
|
||||
|
@ -829,9 +831,18 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped
|
|||
}
|
||||
if (p_break_flags.has_flag(BREAK_WORD_BOUND)) {
|
||||
if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
||||
if ((l_gl[i].flags & GRAPHEME_IS_SOFT_HYPHEN) == GRAPHEME_IS_SOFT_HYPHEN) {
|
||||
uint32_t gl = font_get_glyph_index(l_gl[i].font_rid, l_gl[i].font_size, 0x00ad, 0);
|
||||
float w = font_get_glyph_advance(l_gl[i].font_rid, l_gl[i].font_size, gl)[(orientation == ORIENTATION_HORIZONTAL) ? 0 : 1];
|
||||
if (width + l_gl[i].advance + w <= p_width[chunk]) {
|
||||
last_safe_break = i;
|
||||
word_count++;
|
||||
}
|
||||
} else {
|
||||
last_safe_break = i;
|
||||
word_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND) && word_count == 0) {
|
||||
last_safe_break = i;
|
||||
|
@ -876,6 +887,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do
|
|||
int word_count = 0;
|
||||
bool trim_next = false;
|
||||
|
||||
TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped);
|
||||
int l_size = shaped_text_get_glyph_count(p_shaped);
|
||||
const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped);
|
||||
|
||||
|
@ -889,10 +901,10 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do
|
|||
if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
|
||||
int start_pos = prev_safe_break;
|
||||
int end_pos = last_safe_break;
|
||||
while (trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while (trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
start_pos += l_gl[start_pos].count;
|
||||
}
|
||||
while ((start_pos < end_pos) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
while ((start_pos < end_pos) && ((l_gl[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) {
|
||||
end_pos -= l_gl[end_pos].count;
|
||||
}
|
||||
if (last_end <= l_gl[start_pos].start) {
|
||||
|
@ -949,9 +961,18 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do
|
|||
}
|
||||
if (p_break_flags.has_flag(BREAK_WORD_BOUND)) {
|
||||
if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
||||
if ((l_gl[i].flags & GRAPHEME_IS_SOFT_HYPHEN) == GRAPHEME_IS_SOFT_HYPHEN) {
|
||||
uint32_t gl = font_get_glyph_index(l_gl[i].font_rid, l_gl[i].font_size, 0x00AD, 0);
|
||||
float w = font_get_glyph_advance(l_gl[i].font_rid, l_gl[i].font_size, gl)[(orientation == ORIENTATION_HORIZONTAL) ? 0 : 1];
|
||||
if (width + l_gl[i].advance + w <= p_width) {
|
||||
last_safe_break = i;
|
||||
word_count++;
|
||||
}
|
||||
} else {
|
||||
last_safe_break = i;
|
||||
word_count++;
|
||||
}
|
||||
}
|
||||
if (p_break_flags.has_flag(BREAK_ADAPTIVE) && word_count == 0) {
|
||||
last_safe_break = i;
|
||||
}
|
||||
|
|
|
@ -141,6 +141,7 @@ public:
|
|||
GRAPHEME_IS_CONNECTED = 1 << 10, // Connected to previous grapheme.
|
||||
GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL = 1 << 11, // It is safe to insert a U+0640 before this grapheme for elongation.
|
||||
GRAPHEME_IS_EMBEDDED_OBJECT = 1 << 12, // Grapheme is an object replacement character for the embedded object.
|
||||
GRAPHEME_IS_SOFT_HYPHEN = 1 << 13, // Grapheme is a soft hyphen.
|
||||
};
|
||||
|
||||
enum Hinting {
|
||||
|
|
Loading…
Reference in New Issue