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

World: r3wp

[Postscript] Emitting Postscript from REBOL

Reichart
19-Apr-2008
[1507]
That is the big problem, basically, that as in going across pages 
(or being wide).
Henrik
19-Apr-2008
[1508x2]
I think I have a crude way to do it for one line.
need it for table cells
Reichart
19-Apr-2008
[1510]
I'm working on displaying Qwikis (Wikis) on Cell phones.


It is a connected problem, viewing something intended for one medium 
on another.  

My basic plan is:


- Images - make a thumbnail, then let them click on it to see a larger 
or a list of sizes of their choice


- Tables - Show the name of the table, and then a bias, column or 
row, and offer a search.  Then drill down.


When printing big tables to paper you have to decide what to do if 
the table is simply too big for a single piece of paper.

Put the table at the end on multiple pages?

Put a small version of the table (perhaps unreadable), and say "See 
table on Exhibit X"?
Put the table on multiple pages inline?

Convert the table to something else, for example more like a query 
result, where each row is a chunk of data in a new format?
Henrik
19-Apr-2008
[1511]
looks like getting something so simple as the font height is rather 
difficult in postscript
Graham
19-Apr-2008
[1512]
huh?
Henrik
19-Apr-2008
[1513]
Geomol, I have the structure change needed for text to support the 
font height, so the vertical centering can be made, but I just can't 
find the postscript commands necessary to obtain the font height.
Graham
19-Apr-2008
[1514x2]
you define the font height when you set the font.
and there are postscript commands for getting the size of the text
Henrik
19-Apr-2008
[1516]
the width of the text yes, not the height. and I may not know the 
font at rendering time as that may be set in a completely different 
part of the program.
Graham
19-Apr-2008
[1517x3]
not sure about that .. but you can set a postscript variable to hold 
the latest fontsize and reference that
/fontsize (size) def
I seem to remember justification routines get the word size, drop 
the height value and just work on the width
Henrik
19-Apr-2008
[1520]
stringwidth returns the width and some form of Y value that is not 
the height, but something else.
Graham
19-Apr-2008
[1521x2]
it's the offset from the baseline
The ``charpath'' operator extracts the graphic shapes of its string 
operand and appends them to the current path in the graphic state. 
These shapes can then be processed by other PostScript operators. 
To get the actual size of the area touched by a character a simple 
approach is

	gsave
	newpath
	0 0 moveto
	(X) false charpath flattenpath pathbbox
	grestore


This code places four numbers on the stack, representing the coordinates 
of the lower left and upper right corners of the bounding box enclosing 
the character ``X'' rendered with the current point at (0,0). Leaving 
the flattenpath out will cause it to be less accurate, but it will 
take up less memory and be faster.
Henrik
19-Apr-2008
[1523x3]
how do I call it again, with /fontsize or fontsize?
tried that one, couldn't get it to work.
though not in that form
Graham
19-Apr-2008
[1526]
faq: http://www.postscript.org/FAQs/language/node67.html
Henrik
19-Apr-2008
[1527]
nope, that doesn't work either
Graham
19-Apr-2008
[1528]
what do you mean it doesn't work?
Henrik
19-Apr-2008
[1529x3]
I get a postscript error.
Got the font size to work, but it doesn't take the baseline into 
account.
time for bed... Geomol can take over in the morning. :-)
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
[1554x3]
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.