It does not seem to be using Rasterize[Text[...], "RasterSize"]
nor ImageDimensions[ImageCrop[Graphics[Text[...]]]]
nor Rasterize[Text[...], "BoundingBox"]
(and indeed seems to do the computation differently than png export, which leads me to suspect this might be a bug).
Consider
Rasterize[p1 = With[{nmax = 10},
Graphics[
Table[With[{v = StringJoin @@ Table["a", Mod[n, 2, 1]*10]},
Inset[Text[v],
Offset[ImageDimensions[ImageCrop[Graphics[Text[v]]]]/2 + {3,
0}, {0, n/nmax}], {0, 0}]], {n, 1, nmax}]
]]]
Rasterize[p2 = With[{nmax = 10},
Graphics[
Table[With[{v = StringJoin @@ Table["a", Mod[n, 2, 1]*10]},
Inset[Text[v],
Offset[Rasterize[Text[v], "RasterSize"]/2 + {3, 0}, {0,
n/nmax}], {0, 0}]], {n, 1, nmax}]
]]]
Rasterize[p3 = With[{nmax = 10},
Graphics[
Table[With[{v = StringJoin @@ Table["a", Mod[n, 2, 1]*10]},
Inset[Text[v],
Offset[Rasterize[Text[v], "BoundingBox"][[1 ;; 2]]/2 + {3,
0}, {0, n/nmax}], {0, 0}]], {n, 1, nmax}]
]]]
Export[FileNameJoin[{NotebookDirectory[], "foop1.pdf"}], p1]
Export[FileNameJoin[{NotebookDirectory[], "foop2.pdf"}], p2]
Export[FileNameJoin[{NotebookDirectory[], "foop3.pdf"}], p3]
In Mathematica, only the first one is correctly aligned:
p2 looks like this:
And p3 is similar but not identical. However, when I export to pdf, foop1.pdf looks like this (screenshot):
and foop2.pdf and foop3.pdf look similar. What's going on?