Skip to content

Commit 03bd8ba

Browse files
committed
Merge pull request #107439 from bruvzg/lb_config
Add `line_breaking_strictness` project setting.
2 parents 494cdc3 + e87ccce commit 03bd8ba

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,14 @@
16461646
[b]Note:[/b] "ICU / HarfBuzz / Graphite" text server data includes dictionaries for Burmese, Chinese, Japanese, Khmer, Lao and Thai as well as Unicode Standard Annex #29 and Unicode Standard Annex #14 word and line breaking rules. Data is about 4 MB large.
16471647
[b]Note:[/b] [TextServerFallback] does not use additional data.
16481648
</member>
1649+
<member name="internationalization/locale/line_breaking_strictness" type="int" setter="" getter="" default="0">
1650+
Default strictness of line-breaking rules. Can be overridden by adding [code]@lb={auto,loose,normal,strict}[/code] to the language code.
1651+
- [b]Auto[/b] ([code]0[/code]) - strictness is based on the length of the line.
1652+
- [b]Loose[/b] ([code]1[/code]) - the least restrictive set of line-breaking rules. Typically used for short lines.
1653+
- [b]Normal[/b] ([code]2[/code]) - the most common set of line-breaking rules.
1654+
- [b]Strict[/b] ([code]3[/code]) - the most stringent set of line-breaking rules.
1655+
See [url=https://www.w3.org/TR/css-text-3/#line-break-property]Line Breaking Strictness: the line-break property[/url] for more info.
1656+
</member>
16491657
<member name="internationalization/locale/test" type="String" setter="" getter="" default="&quot;&quot;">
16501658
If non-empty, this locale will be used instead of the automatically detected system locale.
16511659
[b]Note:[/b] This setting also applies to the exported project. To only affect testing within the editor, override this setting with an [code]editor[/code] [url=$DOCS_URL/tutorials/export/feature_tags.html]feature tag[/url] for localization testing purposes.

main/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
26382638
}
26392639

26402640
GLOBAL_DEF_BASIC("internationalization/locale/include_text_server_data", false);
2641+
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/locale/line_breaking_strictness", PROPERTY_HINT_ENUM, "Auto,Loose,Normal,Strict"), 0);
26412642

26422643
OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", true);
26432644
OS::get_singleton()->_allow_layered = GLOBAL_DEF_RST("display/window/per_pixel_transparency/allowed", false);

modules/text_server_adv/text_server_adv.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6513,7 +6513,17 @@ UBreakIterator *TextServerAdvanced::_create_line_break_iterator_for_locale(const
65136513
// Creating UBreakIterator (ubrk_open) is surprisingly costly.
65146514
// However, cloning (ubrk_clone) is cheaper, so we keep around blueprints to accelerate creating new ones.
65156515

6516-
const String language = p_language.is_empty() ? TranslationServer::get_singleton()->get_tool_locale() : p_language;
6516+
String language = p_language.is_empty() ? TranslationServer::get_singleton()->get_tool_locale() : p_language;
6517+
if (!language.contains("@")) {
6518+
if (lb_strictness == LB_LOOSE) {
6519+
language += "@lb=loose";
6520+
} else if (lb_strictness == LB_NORMAL) {
6521+
language += "@lb=normal";
6522+
} else if (lb_strictness == LB_STRICT) {
6523+
language += "@lb=strict";
6524+
}
6525+
}
6526+
65176527
_THREAD_SAFE_METHOD_
65186528
const HashMap<String, UBreakIterator *>::Iterator key_value = line_break_iterators_per_language.find(language);
65196529
if (key_value) {
@@ -8066,12 +8076,14 @@ bool TextServerAdvanced::_is_valid_letter(uint64_t p_unicode) const {
80668076

80678077
void TextServerAdvanced::_update_settings() {
80688078
lcd_subpixel_layout.set((TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout"));
8079+
lb_strictness = (LineBreakStrictness)(int)GLOBAL_GET("internationalization/locale/line_breaking_strictness");
80698080
}
80708081

80718082
TextServerAdvanced::TextServerAdvanced() {
80728083
_insert_num_systems_lang();
80738084
_insert_feature_sets();
80748085
_bmp_create_font_funcs();
8086+
_update_settings();
80758087
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &TextServerAdvanced::_update_settings));
80768088
}
80778089

modules/text_server_adv/text_server_adv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ class TextServerAdvanced : public TextServerExtension {
152152
HashMap<StringName, int32_t> feature_sets;
153153
HashMap<int32_t, FeatureInfo> feature_sets_inv;
154154

155+
enum LineBreakStrictness {
156+
LB_AUTO,
157+
LB_LOOSE,
158+
LB_NORMAL,
159+
LB_STRICT,
160+
};
161+
155162
SafeNumeric<TextServer::FontLCDSubpixelLayout> lcd_subpixel_layout{ TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE };
163+
LineBreakStrictness lb_strictness = LB_AUTO;
156164
void _update_settings();
157165

158166
void _insert_num_systems_lang();

0 commit comments

Comments
 (0)