summaryrefslogtreecommitdiff
path: root/src/haiku_font_support.cc
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-01-03 13:57:13 +0000
committerPo Lu <luangruo@yahoo.com>2022-01-03 13:57:13 +0000
commitab5ee3e29e916d4009b301841e9780aad564a6a0 (patch)
tree87aba92dd6fa03dd496b23e366618d9d7b15a958 /src/haiku_font_support.cc
parentc7768382cc08c6861ed514316a27050b4104fbf4 (diff)
downloademacs-ab5ee3e29e916d4009b301841e9780aad564a6a0.tar.gz
emacs-ab5ee3e29e916d4009b301841e9780aad564a6a0.tar.bz2
emacs-ab5ee3e29e916d4009b301841e9780aad564a6a0.zip
* src/haiku_font_support.cc (BFont_char_bounds): Fix bearings.
Diffstat (limited to 'src/haiku_font_support.cc')
-rw-r--r--src/haiku_font_support.cc31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/haiku_font_support.cc b/src/haiku_font_support.cc
index 298bc73f29e..6ea10b2e47c 100644
--- a/src/haiku_font_support.cc
+++ b/src/haiku_font_support.cc
@@ -126,9 +126,28 @@ BFont_have_char_block (void *font, int32_t beg, int32_t end)
return ft->IncludesBlock (beg, end);
}
-/* Compute bounds for MB_STR, a character in multibyte encoding,
- used with font. The width (in pixels) is returned in ADVANCE,
- the left bearing in LB, and the right bearing in RB. */
+/* Compute bounds for MB_STR, a character in multibyte encoding, used
+ with FONT. The distance to move rightwards before reaching to the
+ next character's left escapement boundary is returned in ADVANCE,
+ the left bearing in LB, and the right bearing in RB.
+
+ The left bearing is the amount of pixels from the left escapement
+ boundary (origin) to the left-most pixel that constitutes the glyph
+ corresponding to mb_str, and RB is the amount of pixels from the
+ origin to the right-most pixel constituting the glyph.
+
+ Both the left and right bearings are positive values measured
+ towards the right, which means that the left bearing will only be
+ negative if the left-most pixel is to the left of the origin.
+
+ The bearing values correspond to X11 XCharStruct semantics, which
+ is what Emacs code operates on. Haiku itself uses a slightly
+ different scheme, where the "left edge" is the distance from the
+ origin to the left-most pixel, where leftwards is negative and
+ rightwards is positive, and the "right edge" is the distance (where
+ leftwards is similarly negative) between the right-most pixel and
+ the right escapement boundary, which is the left escapement
+ boundary plus the advance. */
void
BFont_char_bounds (void *font, const char *mb_str, int *advance,
int *lb, int *rb)
@@ -140,9 +159,9 @@ BFont_char_bounds (void *font, const char *mb_str, int *advance,
ft->GetEdges (mb_str, 1, &edge_info);
ft->GetEscapements (mb_str, 1, &escapement);
- *advance = std::lrint (escapement * size);
- *lb = std::lrint (edge_info.left * size);
- *rb = *advance + std::lrint (edge_info.right * size);
+ *advance = std::ceil (escapement * size);
+ *lb = std::ceil (edge_info.left * size);
+ *rb = *advance + std::ceil (edge_info.right * size);
}
/* The same, but for a variable amount of chars. */