summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-04 08:11:47 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-04 08:11:47 +0300
commit1b6305afa3be18aba38efb451f09fac455806f8e (patch)
tree75171c77bef9b280201016044c968bb716d294b8 /src/ui
parentba34365ca01048110ec372e1e6347fedc4f99740 (diff)
Text: Right-align RTL text lines
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/text.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index 30405bcb..e7f996df 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -1121,6 +1121,15 @@ float horizKern_Font_(iFont *d, uint32_t glyph1, uint32_t glyph2) {
1121} 1121}
1122 1122
1123#if defined (LAGRANGE_ENABLE_HARFBUZZ) 1123#if defined (LAGRANGE_ENABLE_HARFBUZZ)
1124static float glyphRunRightEdge_Font_(const iFont *d, const hb_glyph_position_t *glyphPos, size_t count) {
1125 float x = 0.0f;
1126 for (unsigned int i = 0; i < count; i++) {
1127 const float xAdvance = d->xScale * glyphPos[i].x_advance;
1128 x += xAdvance;
1129 }
1130 return x;
1131}
1132
1124static iRect run_Font_(iFont *d, const iRunArgs *args) { 1133static iRect run_Font_(iFont *d, const iRunArgs *args) {
1125 const int mode = args->mode; 1134 const int mode = args->mode;
1126 iRect bounds = zero_Rect(); 1135 iRect bounds = zero_Rect();
@@ -1168,6 +1177,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1168 } 1177 }
1169 } 1178 }
1170 hb_buffer_clear_contents(hbBuf); 1179 hb_buffer_clear_contents(hbBuf);
1180 iBool isRunRTL = iFalse;
1171 /* Cluster values are used to determine offset inside the UTF-8 source string. */ 1181 /* Cluster values are used to determine offset inside the UTF-8 source string. */
1172 //hb_buffer_set_cluster_level(hbBuf, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); 1182 //hb_buffer_set_cluster_level(hbBuf, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
1173#if defined (LAGRANGE_ENABLE_FRIBIDI) 1183#if defined (LAGRANGE_ENABLE_FRIBIDI)
@@ -1200,6 +1210,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1200 NULL, 1210 NULL,
1201 data_Array(&visToLog), 1211 data_Array(&visToLog),
1202 NULL); 1212 NULL);
1213 if (FRIBIDI_IS_RTL(baseDir)) {
1214 isRunRTL = iTrue;
1215 }
1203 const FriBidiStrIndex *visToLogIndex = constData_Array(&visToLog); 1216 const FriBidiStrIndex *visToLogIndex = constData_Array(&visToLog);
1204 const FriBidiStrIndex *logToRunIndex = constData_Array(&logToRun); 1217 const FriBidiStrIndex *logToRunIndex = constData_Array(&logToRun);
1205 iConstForEach(Array, v, &vis32) { 1218 iConstForEach(Array, v, &vis32) {
@@ -1222,7 +1235,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1222 } 1235 }
1223 else break; 1236 else break;
1224 } 1237 }
1225#endif 1238#endif
1226 hb_buffer_set_content_type(hbBuf, HB_BUFFER_CONTENT_TYPE_UNICODE); 1239 hb_buffer_set_content_type(hbBuf, HB_BUFFER_CONTENT_TYPE_UNICODE);
1227 hb_buffer_set_direction(hbBuf, HB_DIRECTION_LTR); 1240 hb_buffer_set_direction(hbBuf, HB_DIRECTION_LTR);
1228 /* hb_buffer_set_script(hbBuf, HB_SCRIPT_LATIN); */ /* will be autodetected */ 1241 /* hb_buffer_set_script(hbBuf, HB_SCRIPT_LATIN); */ /* will be autodetected */
@@ -1311,6 +1324,11 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1311 } 1324 }
1312 } 1325 }
1313 } 1326 }
1327 /* Right-align RTL runs. */
1328 if (isRunRTL && xCursor < 1 && args->xposLayoutBound > 0) {
1329 xCursor += args->xposLayoutBound - orig.x -
1330 glyphRunRightEdge_Font_(run->font, glyphPos, glyphCount);
1331 }
1314 /* We have determined a possible wrap position inside the text run, so now we can 1332 /* We have determined a possible wrap position inside the text run, so now we can
1315 draw the glyphs. */ 1333 draw the glyphs. */
1316 for (unsigned int i = 0; i < glyphCount; i++) { 1334 for (unsigned int i = 0; i < glyphCount; i++) {
@@ -1345,7 +1363,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1345 } 1363 }
1346 } 1364 }
1347 else { 1365 else {
1348 bounds.size.x = iMax(bounds.size.x, dst.x + dst.w); 1366 bounds.size.x = iMax(bounds.size.x, dst.x + dst.w - orig.x);
1349 bounds.size.y = iMax(bounds.size.y, yCursor + glyph->font->height); 1367 bounds.size.y = iMax(bounds.size.y, yCursor + glyph->font->height);
1350 } 1368 }
1351 if (mode & draw_RunMode && *textPos != 0x20) { 1369 if (mode & draw_RunMode && *textPos != 0x20) {