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

World: r3wp

[Postscript] Emitting Postscript from REBOL

Gabriele
18-Apr-2006
[716]
Graham: yes, and data is parsed from the Adobe Font Metrics file 
and included in pdf-maker.r for the 14 standard postscript fonts.
Graham
18-Apr-2006
[717x2]
Henrik, my latest demo has a button that prints to the parallel port. 
 As for choosing trays and paper size, I think you can set that in 
the postscript comments.
Gabriele, do you have a reference on how to use this font metric 
data ?
Henrik
18-Apr-2006
[719]
is there a method to center text?
Graham
18-Apr-2006
[720]
I used a ruler :)
Henrik
18-Apr-2006
[721]
darn it
Graham
18-Apr-2006
[722]
Ok, let's be serious
Henrik
18-Apr-2006
[723]
hmm... at least measure the size of the text
Graham
18-Apr-2006
[724x3]
You can determine the size of the text based on the current point 
size
and you know the page size
so, you can center it in draw.
Henrik
18-Apr-2006
[727]
hmm... that would give me the height of the text, but not the width
Graham
18-Apr-2006
[728x3]
isn't there a textinfo thing that tells you the width of text?
there is also a stringwidth command in postscript.
so, my approach would be to create a center dialect word, and have 
a postscript implementation and a draw implementation
Henrik
18-Apr-2006
[731]
textinfo doesn't seem to work inside draw
Graham
18-Apr-2006
[732x2]
presumably you can use it in vid and use those values.
fair enough?
Henrik
18-Apr-2006
[734x2]
quite a detour...
but OK, I only need to calculate it for two lines of text right now
Graham
18-Apr-2006
[736]
>> layout [ a: text "this is a line" font [ size: 20 ]]
>> line-list: make system/view/line-info []
>> textinfo a line-list 0
>> probe line-list
make object! [
    start: "this is a line"
    num-chars: 14
    offset: 2x2
    size: 104x23
]
>> layout [ a: text "this is a line" font [ size: 12 ]]
>> textinfo a line-list 0
>> probe line-list
make object! [
    start: "this is a line"
    num-chars: 14
    offset: 2x2
    size: 68x15
]
Henrik
18-Apr-2006
[737x2]
could be possible to simplify that...
isn't there a SIZE-TEXT function?
Graham
18-Apr-2006
[739x2]
dunno
still needs a face
Henrik
18-Apr-2006
[741]
>> size-text make face [text: "hello"]
== 29x15
Graham
18-Apr-2006
[742]
easier :)
Henrik
18-Apr-2006
[743]
throw in a font definition
Graham
18-Apr-2006
[744]
example?
Henrik
18-Apr-2006
[745x4]
well, just the one used in DRAW for the text that needs to be printed
center: func [text width font] [
  width / 2 - second size-text make face compose [
    text: (text)
    font: (font)
  ]
]
that's what it takes
but it only works sometimes.. I don't know why
Graham
18-Apr-2006
[749]
copy
Henrik
18-Apr-2006
[750]
found the bug
Graham
18-Apr-2006
[751]
compose copy [ ]
Henrik
18-Apr-2006
[752]
size-text is the limit of the size of the face as well
Graham
18-Apr-2006
[753]
oh ..
Henrik
18-Apr-2006
[754x9]
center: func [text width font] [
  (width / 2) - (first size-text make face compose copy [
    text: (text)
    font: (font)
    size: (as-pair width 100)
  ])
]
hmm... maybe a different one is better...
center: func [text size font] [
  (size/x / 2) - (first size-text make face compose copy [
    text: (text)
    font: (font)
    size: (size)
  ])
]
center: func [text size font] [
  divide subtract size/x first size-text make face compose copy [
    text: (text)
    font: (font)
    size: (size)
  ] 2
]
getting better :-)
offsets a few pixels to the left, but it seems to center the text
the offset gets bigger when using a larger font.. wonder what causes 
it
anyhoo:


img: draw make image! 297x210 compose [pen red font (make face/font 
[size: 30]) text (as-pair center "BOOM!" 297x210 make face/font [size: 
30] 20) "BOOM!"]
view layout [image img]
I hope this can be done a little prettier...
Henrik
19-Apr-2006
[763]
http://www.hmkdesign.dk/run14.png<--- the offset can be seen at 
the bottom. I haven't tested, but maybe the kerning between the VID 
and DRAW font rendering isn't the same.
Geomol
19-Apr-2006
[764]
That looks like a nice little application! :-) Nice!
Henrik
19-Apr-2006
[765]
been working on that thing for way too long... but hopefully it can 
be completed now