Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Font Dealing 2

This thread is locked; no one can reply to it. rss feed Print
Font Dealing 2
hossein
Member #7,312
June 2006

hi again
as i remember we had a settextjustify function in Turbo c but i dont know its equal
function in allegro .
corresponding function.
thanks alot.

Evert
Member #794
November 2000
avatar

man textprintf_ex said:

SEE ALSO
font(3), textout_ex(3), textprintf_centre_ex(3),
textprintf_right_ex(3), textprintf_justify_ex(3), text_height(3),
text_length(3), uszprintf(3)

Emphasis mine.

miran
Member #2,407
June 2002

Is there a reason you can't reply in the first thread?

--
sig used to be here

hossein
Member #7,312
June 2006

hi evert
i tried what you said but didnt got desired goal.
main problem was that i coudlnt justify text as horizontal or vertical.
please help me to solve that .
i am asking miran too because it seems so professional in this field.
help me miran,evert,or my friends.
bye.

Evert
Member #794
November 2000
avatar

Quote:

Is there a reason you can't reply in the first thread?

Saw this one first?

Quote:

main problem was that i coudlnt justify text as horizontal or vertical.

What do you mean by justify horizontal or vertical?

miran
Member #2,407
June 2002

Quote:

Saw this one first?

Sorry, I was talking to the OP. He started a thread with an almost identical question before, I gave him an answer (although not as detailed as yours), after which he proceeded to start this one.

--
sig used to be here

Evert
Member #794
November 2000
avatar

Ah, ok.

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

hi evert
i tried what you said but didnt got desired goal.
main problem was that i coudlnt justify text as horizontal or vertical.
please help me to solve that .
i am asking miran too because it seems so professional in this field.
help me miran,evert,or my friends.
bye.

If you mean rendering text top-down instead of left-right: You can't, really. This would involve rotating characters, something which is not implemented in allegro's text api.
To achieve vertical text output, here's what you can do. First, you use text_length() and text_height() to find the text's size in pixels. Create a memory bitmap of that same size, and fill it with the transparent color (magic pink / #0; bitmap_mask_color() will give you the correct value). Render the text normally onto the memory bitmap. Then use pivot_sprite() to draw the text wherever you want it. Remember that draw_sprite() expects angles in fixed-point, 256-degrees format, so to rotate the text by 90 degrees, you need to use itofix(64) as the angle. Finally, don't forget to clean up the temporary bitmap.
So:

void textout_vertical(BITMAP* bmp, const FONT* font, const char* str, int x, int y, int fg, int bg) {
  int w = text_length(font, str);
  int h = text_height(font);
  BITMAP* buf = create_bitmap(w, h);
  clear_to_color(buf, bitmap_mask_color(buf));
  textout_ex(buf, font, str, 0, 0, fg, bg);
  pivot_sprite(bmp, buf, x, y, 0, h, itofix(64));
  destroy_bitmap(buf);
}

This should do the trick.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Go to: