r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Postscript] Emitting Postscript from REBOL

Graham
19-Apr-2008
[1532]
aren't you both in the same timezone?
Henrik
19-Apr-2008
[1533]
yes
Henrik
20-Apr-2008
[1534x5]
yes! got grahams method working now. thanks.
it also helps better top alignment
Geomol, you may find my changes here:

http://hmkdesign.dk/rebol/postscript.r
The changes are:


- Stores the font size inside PS every time a new font is selected. 
This is not used however, but perhaps is useful in the future.

- Added bottom, middle and top alignment for TEXT. Similarly to how 
you specify a size for LEFT, CENTER and RIGHT, you can enter a size 
for TOP, MIDDLE and BOTTOM:

Some text
 center 400 middle 200

Both sets are optional. The default alignment is LEFT and BOTTOM.

My changes are marked HMK in the source. I hope it is of use.
now it would be nice with some form of margin management
Geomol
20-Apr-2008
[1539]
I was looking at the postscript operator STRINGWIDTH. It seems to 
be able to take two arguments, for x and y width. Are you using that?
Henrik
20-Apr-2008
[1540x5]
I use it only for X. The Y component is not a height, but something 
else.
it has something to do with offsetting from the glyph origin, I think
but now I have margin working too. it was simple to add.
updated source code for download
allegedly the method graham describes is not very efficient, but 
it works accurately and that's what I want.
Geomol
20-Apr-2008
[1545x2]
Yes, the y width seems to be for vertical writing, like in chinese.
I'll take a look at your changes...
Henrik
20-Apr-2008
[1547x6]
moved the source to http://hmkdesign.dk/rebol/postscript/postscript.r
example of adjustments: http://hmkdesign.dk/rebol/postscript/testsheet.ps
(table is my own component, not part of postscript.r :-))
Geomol, there is some code duplication in there. Perhaps it can be 
optimized?
seems it's still not accurate :-( it still calculates the baseline 
incorrectly when using letters like "g"
so if the bounding box does that for a single word, we need to use 
all chars in the alphabet to calculate the height correctly for any 
char combination. it does not do that right now
Geomol
20-Apr-2008
[1553]
If vertical position should be in the dialect, I think, it should 
be based on a real postscript feature. If such a thing isn't found 
in postscript, it should be implemented on a higher level, shouldn't 
it?
Henrik
20-Apr-2008
[1554x4]
The problem is to get the height accurately for all glyphs for a 
font (I just got that now). Some fonts have very high tops and very 
low bottoms and you want that to work for any font and letter combination 
we throw at it. it would be harder to get that information inside 
REBOL than inside postscript.
I got it rendered now so that the vertical position is at least consistent 
now, but the font is offset a few points too far down. I don't know 
why yet, but it's probably the baseline again.
there is another method which is to get the bbox information from 
the font metric file itself. it's much faster, since it's just lookup, 
but I couldn't find an example of how to read it.
so my current method is Graham's, except for calculating the entire 
alphabet. we should probably work on getting that information from 
the font metric file instead.
Geomol
20-Apr-2008
[1558x2]
In Adobe documentation, they operate with "character origin", which 
is the baseline, I think. If you do:
40 50 moveto (ABC) show
, the origin of the A letter is at coordinate (40, 50).
So it doesn't matter, how high the font is.
Henrik
20-Apr-2008
[1560]
you still need to know the size of the bbox, don't you?
Geomol
20-Apr-2008
[1561x2]
A vertical positioning would be a simple calculation. Say, you want 
the baseline to be positioned at the middle of a 300 point high box 
starting at pos (100, 100). You then start by putting text at coord 
(100, 250).
The y coord is 300 / 2 plus the 100 = 250.
Henrik
20-Apr-2008
[1563]
that assumes that the text is rendered from its own center point. 
it isn't, is it?
Geomol
20-Apr-2008
[1564x2]
If you wanna build a table, you calculate the position of each line 
like this, and send the precise coords to the postscript dialect. 
It would probably be best to build a new dialect on top of the postscript 
one, and in that dialect handle the calculations.
No, text is rendered from the "character origin" (the baseline), 
which can be different than the center of the text. This should probably 
be taken care of, if needed. hm
Henrik
20-Apr-2008
[1566x2]
the table is a different matter :-) it's already done, not yet as 
a dialect though. I will build one later.
The baseline problem is the one I'm hunting a solution for. About 
the font metrics, the bbox for the whole font is stored in FontBBox 
in the font dictionary.
Geomol
20-Apr-2008
[1568]
If your goal is, that the text is completely centered vertically, 
then you have a problem. Because how do you know, what characters 
to be written? If there is no 'g' in the word, you need to position 
it a bit lower, than if you had 'g' in the text, for it to be completely 
middle aligned.
Henrik
20-Apr-2008
[1569x3]
that you solve by calculating the bbox for the entire alphabet instead 
of just the words you write
this way the height will be constant
and this information shouldn't need to be calced if we can get that 
from FontBBox in the font dictionary. still hunting for how to obtain 
it. :-)
Geomol
20-Apr-2008
[1572]
Ok, I'm a bit lost. I'm not completely sure, what you're trying to 
achieve.
Henrik
20-Apr-2008
[1573x6]
accurately vertically centered text
what I did at first was just to use the font size. that doesn't work, 
because it does not take the baseline into account.
then I used Graham's method and it does practically the same thing 
(I forgot to test for letters like "g"), but you can successfully 
calculate the bbox for a text string this way, if you need it.
Combining Graham's method with getting the height from the entire 
alphabet instead of the single word would eliminate the varying height 
problem you mention. But the baseline problem turns up again.
The bbox information for the entire font is stored in each font metric 
file as a [llx, lly, urx, ury] coordinate set, so I shouldn't need 
to calculate it. This information is crucial in order to get one 
line of vertically centered text. I already got everything in place 
except that particular number. :-)
the source you are reading contains Graham's method
Geomol
20-Apr-2008
[1579]
Isn't this centered?

PageSize A4
page [
	font [Times 40] linewidth 0
	at 0x421 "Centered text" center 595
]
Henrik
20-Apr-2008
[1580]
well, that's hardcoded :-)
Geomol
20-Apr-2008
[1581]
Yes, that's what I think, you should do. Build a dialect with keywords 
as top, middle, bottom etc. and make that dialect know the size of 
the paper and correctly calculate the positions. That's the way to 
do it, I think. I would do it like that.