inline style questions

17 views
Skip to first unread message

baldtrol

unread,
Oct 22, 2008, 10:27:56 AM10/22/08
to Prawn
Hi All,

I know as of .2.x inline styles aren't supported. I've "rolled my
own" solution for the most part, but I'm unfortunately stuck. I'm
able to split strong/b/i/em tags across correct ranges of text, and
add styles appropriately. However, as :hold_position isn't active in .
2.x either, I've been trying to figure out how to hack together a
working solution for it. I've looked at the inline_styles3 branch on
github, trying to figure out where/how in document/text.rb to steal
ideas. I've seen what looks like some progress there, but I admit,
I'm enough of a prawn n00b to not entirely "get" what's going on.

Effectively, I can take strings like "i am <b>some bold</b> and
<i>very exciting</i> text" and turn it into the appropriate segments,
but i don't understand the inner workings of font, width_of, bounds,
etc, to correctly determine the :at positions. I've tried figuring
out the correct x and y positions from context, but I'm not getting
it.

Does anyone have any suggestions or pointers? I'd really like to
continue to use Prawn for this project, it's a really elegant piece of
work, and for my rails app is substantially easier to use and leverage
than pdf::writer and .rpdf templates. Still, the lack of inline
styles will be a showstopper for me if I can't out-smart it ;)

Thanks!
Pete

thorny_sun

unread,
Oct 22, 2008, 11:00:17 AM10/22/08
to Prawn
some info that might help:
1) :at specifies the baseline position. without the :at, you are
using the current y value which will specify the top edge of the text
(including a line gap)
2) font.height is equal to the ascender + descender + line_gap
3) and remember each font style will have different values for these
4) descender is actually a negative value so font.height is more
accurately ascender-descender+line_gap

I actually created a pdf to help me understand at a glance, check it
out: http://www.cracklabs.com/prawnto/prawnto_demos/font_measurements.pdf

Knowing these things will hopefully help you along.

I ended up doing a similar thing-- rolling my own style stuff. But I
never got to the point where I was taking into account any wrapping so
I didn't bother publishing. Do let us all know if you manage to
tackle this problem!

-thorny_sun

baldtrol

unread,
Oct 22, 2008, 12:38:51 PM10/22/08
to Prawn
Thanks, that does help some!

I'm a little further along, but I'm again pleading ignorance. what's
the "right" way to determine the current "y" value of the page? I've
been trying permutations of pdf.y with some manipulation, but not
having a lot of luck.

In effect, I have a set of items that need to act like nested
<ul><li><ul><li></li></ul></li></ul> sets, to make bulleted and sub-
bulleted lists.

I don't know any other way to "indent" a section of text other than to
give it an "at" value. I've tried cell and bounding_box, but you
still have to tell them "where" to start. What's the right way, if
there is one, to let the "y" value be effectively dynamic, while
pushing the x value across the page?

Thanks again!

Pete

Gregory Brown

unread,
Oct 22, 2008, 12:41:50 PM10/22/08
to prawn...@googlegroups.com
On Wed, Oct 22, 2008 at 12:38 PM, baldtrol <bald...@gmail.com> wrote:
>
> Thanks, that does help some!
>
> I'm a little further along, but I'm again pleading ignorance. what's
> the "right" way to determine the current "y" value of the page? I've
> been trying permutations of pdf.y with some manipulation, but not
> having a lot of luck.

y relative to the current bounding box (or the margins)

pdf.y - pdf.bounds.absolute_bottom

--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

baldtrol

unread,
Oct 22, 2008, 12:47:46 PM10/22/08
to Prawn
Thanks Greg... I looked at that, but that gives me relative to the
bounding box, not to the text that was above it. if i have variable
length text above that in the bounding box, which i do, then that
still acts as an "absolute" position for all intents and purposes,
unless I'm mistaken? (which i totally could be, like i said, i'm just
reading documentation, looking at the code on github, and trying
things :) )

On Oct 22, 12:41 pm, "Gregory Brown" <gregory.t.br...@gmail.com>
wrote:

Gregory Brown

unread,
Oct 22, 2008, 12:51:41 PM10/22/08
to prawn...@googlegroups.com
On Wed, Oct 22, 2008 at 12:47 PM, baldtrol <bald...@gmail.com> wrote:
>
> Thanks Greg... I looked at that, but that gives me relative to the
> bounding box, not to the text that was above it. if i have variable
> length text above that in the bounding box, which i do, then that
> still acts as an "absolute" position for all intents and purposes,
> unless I'm mistaken? (which i totally could be, like i said, i'm just
> reading documentation, looking at the code on github, and trying
> things :) )

It is (basically) pointless to try to implement inline styles when
there are still serious issues with font height in Prawn and also a
change in the way text is positioned in the 0.3 codebase.
Unfortunately, I will need to fix these longstanding issues (or
someone else will) before it makes any sense to try to implement it
using broken calculations.

-greg

thorny_sun

unread,
Oct 22, 2008, 1:00:41 PM10/22/08
to Prawn
pdf.y is the absolute y position on the page-- whenever you use the
text method this will advance down the page
pdf.bounds.absolute_bottom is the absolute y position of the bottom of
your current bounding box

and so pdf.y - pdf.bounds.absolute_bottom gives you the current
relative y position in your bounding box.

if you're using bounding boxes, then y is moved to the top edge of
your bounding box.
and remember if you're using the :at option, then you are specifying
the baseline location
without the :at options, the baseline will be at pdf.y-(font.height
+font.descender)

-thorny_sun

baldtrol

unread,
Oct 22, 2008, 1:38:35 PM10/22/08
to Prawn
ah-hah! then I just misunderstood. Thank you!
Reply all
Reply to author
Forward
0 new messages