我的程序读取 PDF 并尝试在用户 space 中找到每个字形的坐标
My program reads PDF and try to find coordinate of each glyph in user space
它是这样的
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 4101 267 389 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 4853 267 25 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 5241 267 25 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
1090 578 3081 1988 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
603 586 m
603 1800 l
649 1800 l
649 586 l
h
W n
8.3336724 0 0 8.3336724 0 0 cm
BT
/T1_0 5.04 Tf
0 1.0002 -1 0 76.8 70.32 Tm
(J)Tj
请问J的坐标应该是什么?
我的裁剪框是 0 0 612 792 ,旋转值为 90.
据我所知
Th=1 默认,
Tfs=5.04,从 {/T1_0 5.04 Tf}
Trise=0 默认,
测试状态矩阵
5.04 1 0
0 5.04 0
0 0 1
Tm
0 1.0002 0
-1 0 0
76.8 70.32 1
TRM = 文本状态矩阵 X Tm
-1 5.041 0
-5.040 0 0
76.800 70.320 1
所以
[x,y,1] = [76.8, 70.32, 1] X TRM = [-354.413 457.469 1]
所以用户 space 中的 x 坐标将变为负数。你能解释一下我做错了什么吗?
OP计算的矩阵Trm为
-1 5.041 0
-5.040 0 0
76.800 70.320 1
是文本渲染矩阵PDF规范中描述如下:
Conceptually, the entire transformation from text space to device space may be represented by a text rendering matrix, Trm:
(section 9.4.2, ISO 32000-1:2008)
OP 的错误不在计算 这个矩阵,而是在 使用 它:这个矩阵包含 整个转换从文本 space 到设备 space,
Tj and other text-showing operators shall position the origin of the first glyph to be painted at the origin of text space.
(section 9.2.4 ISO 32000-1:2008)
和
The glyph origin is the point (0, 0) in the glyph coordinate system
(ibidem)
因此,要确定 OP 的位置
(J)Tj
放置字形的原点 J
,必须将该矩阵应用于原点 (0, 0)
,而不是像 OP 那样应用于 (76.8, 70.32)
。
因此,
[x,y,1] = [0, 0, 1] X Trm = [76.8, 70.32, 1]
即J
的坐标在设备 space 中是 (76.8, 70.32)
。由于 OP 假设初始转换矩阵是单位矩阵,因此该设备 space 本质上是默认用户 space.
不幸的是,OP 没有解释他正在寻找的坐标系中的坐标。因此,这些坐标很可能不是他要找的坐标。
它是这样的
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 4101 267 389 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 4853 267 25 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 5241 267 25 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
1090 578 3081 1988 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
603 586 m
603 1800 l
649 1800 l
649 586 l
h
W n
8.3336724 0 0 8.3336724 0 0 cm
BT
/T1_0 5.04 Tf
0 1.0002 -1 0 76.8 70.32 Tm
(J)Tj
请问J的坐标应该是什么? 我的裁剪框是 0 0 612 792 ,旋转值为 90.
据我所知
Th=1 默认,
Tfs=5.04,从 {/T1_0 5.04 Tf}
Trise=0 默认,
测试状态矩阵
5.04 1 0
0 5.04 0
0 0 1
Tm
0 1.0002 0
-1 0 0
76.8 70.32 1
TRM = 文本状态矩阵 X Tm
-1 5.041 0
-5.040 0 0
76.800 70.320 1
所以
[x,y,1] = [76.8, 70.32, 1] X TRM = [-354.413 457.469 1]
所以用户 space 中的 x 坐标将变为负数。你能解释一下我做错了什么吗?
OP计算的矩阵Trm为
-1 5.041 0 -5.040 0 0 76.800 70.320 1
是文本渲染矩阵PDF规范中描述如下:
Conceptually, the entire transformation from text space to device space may be represented by a text rendering matrix, Trm:
(section 9.4.2, ISO 32000-1:2008)
OP 的错误不在计算 这个矩阵,而是在 使用 它:这个矩阵包含 整个转换从文本 space 到设备 space,
Tj and other text-showing operators shall position the origin of the first glyph to be painted at the origin of text space.
(section 9.2.4 ISO 32000-1:2008)
和
The glyph origin is the point (0, 0) in the glyph coordinate system
(ibidem)
因此,要确定 OP 的位置
(J)Tj
放置字形的原点 J
,必须将该矩阵应用于原点 (0, 0)
,而不是像 OP 那样应用于 (76.8, 70.32)
。
因此,
[x,y,1] = [0, 0, 1] X Trm = [76.8, 70.32, 1]
即J
的坐标在设备 space 中是 (76.8, 70.32)
。由于 OP 假设初始转换矩阵是单位矩阵,因此该设备 space 本质上是默认用户 space.
不幸的是,OP 没有解释他正在寻找的坐标系中的坐标。因此,这些坐标很可能不是他要找的坐标。