mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-24 00:45:49 +02:00
Vertically center the glyphs in comb text fields
This commit is contained in:
parent
59df671552
commit
34516bcec3
@ -2574,9 +2574,6 @@ class WidgetAnnotation extends Annotation {
|
|||||||
fontSize,
|
fontSize,
|
||||||
totalWidth,
|
totalWidth,
|
||||||
totalHeight,
|
totalHeight,
|
||||||
defaultVPadding,
|
|
||||||
descent,
|
|
||||||
lineHeight,
|
|
||||||
alignment,
|
alignment,
|
||||||
bidi(lines[0]).dir === "rtl",
|
bidi(lines[0]).dir === "rtl",
|
||||||
annotationStorage
|
annotationStorage
|
||||||
@ -2938,9 +2935,6 @@ class TextWidgetAnnotation extends WidgetAnnotation {
|
|||||||
fontSize,
|
fontSize,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
vPadding,
|
|
||||||
descent,
|
|
||||||
lineHeight,
|
|
||||||
alignment,
|
alignment,
|
||||||
isRTL,
|
isRTL,
|
||||||
annotationStorage
|
annotationStorage
|
||||||
@ -2977,11 +2971,18 @@ class TextWidgetAnnotation extends WidgetAnnotation {
|
|||||||
previousWidth = glyphWidth;
|
previousWidth = glyphWidth;
|
||||||
}
|
}
|
||||||
const renderedComb = buf.join(" ");
|
const renderedComb = buf.join(" ");
|
||||||
|
|
||||||
|
// Vertically center the glyphs within the field: comb fields are mostly
|
||||||
|
// filled with uppercase letters and/or digits, hence we use the cap height
|
||||||
|
// (with a fallback on the ascent or the font size) to center them.
|
||||||
|
const vShift =
|
||||||
|
(height - (font.capHeight || font.ascent || 1) * fontSize) / 2;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
`/Tx BMC q ${colors}BT ` +
|
`/Tx BMC q ${colors}BT ` +
|
||||||
defaultAppearance +
|
defaultAppearance +
|
||||||
` 1 0 0 1 ${numberToString(hShift)} ${numberToString(
|
` 1 0 0 1 ${numberToString(hShift)} ${numberToString(
|
||||||
vPadding + descent
|
vShift
|
||||||
)} Tm ${renderedComb}` +
|
)} Tm ${renderedComb}` +
|
||||||
" ET Q EMC"
|
" ET Q EMC"
|
||||||
);
|
);
|
||||||
|
|||||||
@ -2054,7 +2054,7 @@ describe("annotation", function () {
|
|||||||
annotationStorage
|
annotationStorage
|
||||||
);
|
);
|
||||||
expect(appearance).toEqual(
|
expect(appearance).toEqual(
|
||||||
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 3.07 Tm" +
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 3.21 Tm" +
|
||||||
" 2.61 0 Td (a) Tj 8 0 Td (a) Tj 8.56 0 Td (\\() Tj" +
|
" 2.61 0 Td (a) Tj 8 0 Td (a) Tj 8.56 0 Td (\\() Tj" +
|
||||||
" 7.44 0 Td (a) Tj 8 0 Td (a) Tj" +
|
" 7.44 0 Td (a) Tj 8 0 Td (a) Tj" +
|
||||||
" 8.56 0 Td (\\)) Tj 7.44 0 Td (a) Tj" +
|
" 8.56 0 Td (\\)) Tj 7.44 0 Td (a) Tj" +
|
||||||
@ -2095,7 +2095,7 @@ describe("annotation", function () {
|
|||||||
annotationStorage
|
annotationStorage
|
||||||
);
|
);
|
||||||
expect(appearance).toEqual(
|
expect(appearance).toEqual(
|
||||||
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 3.07 Tm" +
|
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 2.5 Tm" +
|
||||||
" 1.5 0 Td (\x30\x53) Tj 8 0 Td (\x30\x93) Tj 8 0 Td (\x30\x6b) Tj" +
|
" 1.5 0 Td (\x30\x53) Tj 8 0 Td (\x30\x93) Tj 8 0 Td (\x30\x6b) Tj" +
|
||||||
" 8 0 Td (\x30\x61) Tj 8 0 Td (\x30\x6f) Tj" +
|
" 8 0 Td (\x30\x61) Tj 8 0 Td (\x30\x6f) Tj" +
|
||||||
" 8 0 Td (\x4e\x16) Tj 8 0 Td (\x75\x4c) Tj" +
|
" 8 0 Td (\x4e\x16) Tj 8 0 Td (\x75\x4c) Tj" +
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user