ErlGuten question

Mikael Karlsson mikael.karlsson@REDACTED
Wed Apr 9 22:38:19 CEST 2003


Hi Chris,
for the low level;
I think this works for erlguten 2.1.

/Mikael

get_string_width(PID, Fontname, PointSize, Str)->
    FontIndex = pdf:get_font_alias(PID, Fontname),
    trunc(erlguten_line_break:sizeof(FontIndex, Str) * PointSize/1000).

%% Example, usage for right alignment ---
pageno(PDF)->
    pdf:begin_text(PDF),
    pdf:set_font(PDF,"Times-Roman", 11),
    A = pdf:get_page_no(PDF),
    Str = "Page " ++ pdf:n2s(A),
    Width = pdf:get_string_width(PDF,"Times-Roman", 11, Str),
%%    io:fwrite("Width is :~p~n", [Width]),
    case A rem 2 of
        0 ->
            pdf:set_text_pos(PDF, 100, 50);
        1 ->
            pdf:set_text_pos(PDF, 510 - Width, 50)
    end,
    pdf:text(PDF, Str),
    pdf:end_text(PDF).
---

onsdag 09 april 2003 21:46 skrev Chris Pressey:
> Does anyone know of a way to right-align text with ErlGuten?
>
> There doesn't seem to be an option for it in the galley files.
>
> Also, there isn't anything like pdf:get_text_width(PDF, String), which
> is what I'd use if I were trying it on a lower (non-XML) level - I tried
> adding it but it looks like erlguten_font_server doesn't know anything
> about the metrics of built-in fonts (but logically this can't be the
> case, I must be doing something wrong with the font index.)
>
> -Chris




More information about the erlang-questions mailing list