Different size labels

8 posts / 0 new
Last post
walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Different size labels

Hello guys,
I am trying to create some Reaction labels with different font size, which should be the screen font, only reduced by specific points.

I was looking at the autodocs and I saw that IA_FONT is deprecated, and we need to use LABEL_DrawInfo, which actually includes a TextAttr, which looks similar to the one that IA_FONT used.

What I would like to ask is, am I at the right path? Is LABEL_DrawInfo what I should use?
Is there a way to get the current font and font size and reduce it by some points?
Is there an automatic process that does that, i.e. like saying screen->fontSize - 2?
Where can I find more info on LABEL_DrawInfo?

Thanks a lot for your help.

OldFart
OldFart's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2010-11-30 14:09
Re: Different size labels

@walkero

Is there a way to get the current font and font size and reduce it by some points?
Is there an automatic process that does that, i.e. like saying screen->fontSize - 2?

A long time ago a built these two functions, one being the counterpart of the other and finally the way they are called:

  1. struct TextAttr *Retrieve_FontPrefs(struct ExecParam *xn, uint16 Entry)
  2. {
  3. INFO_ENTER
  4. struct TextAttr *ta = NULL;
  5.  
  6. struct IFFHandle *iff = IIFF->AllocIFF();
  7.  
  8. if (iff)
  9. {
  10. if ((iff->iff_Stream = (LONG)IDOS->Open("ENVARC:Sys/font.prefs", MODE_OLDFILE)))
  11. {
  12. IIFF->InitIFFasDOS(iff);
  13.  
  14. LONG Error = IIFF->OpenIFF(iff, IFFF_READ);
  15.  
  16. if (Error == IFFERR_NOERROR)
  17. {
  18. if (IIFF->StopChunk(iff, ID_PREF, ID_FONT) == IFFERR_NOERROR)
  19. {
  20. BOOL Done = FALSE;
  21. struct ContextNode *cn;
  22.  
  23. while (
  24. ((Error = IIFF->ParseIFF(iff, IFFPARSE_SCAN)) == IFFERR_NOERROR) &&
  25. (Done == FALSE)
  26. )
  27. {
  28. if ((cn = IIFF->CurrentChunk(iff)) != NULL)
  29. {
  30. char FONT_Buff[cn->cn_Size];
  31.  
  32. IIFF->ReadChunkBytes(iff, FONT_Buff, cn->cn_Size);
  33.  
  34. if (((*(uint16 *)(FONT_Buff+14)) == Entry))
  35. {
  36. ta = ALLOCATE_STRUCT(xn->xn_MemPool, struct TextAttr);
  37.  
  38. if (ta != NULL)
  39. {
  40. ALLOCOPY_STRING(xn->xn_MemPool, ta->ta_Name, ((STRPTR)(FONT_Buff+28)), 0);
  41. ta->ta_YSize = (*(uint16 *)(FONT_Buff+24));
  42. }
  43. ELSE_ERROR("Allocate structure (TextAttr)");
  44.  
  45. Done = TRUE;
  46. }
  47. }
  48. }
  49. }
  50. ELSE_ERROR("Prop Chunk");
  51.  
  52. IIFF->CloseIFF(iff);
  53. }
  54. ELSE_ERROR("Open IFF");
  55.  
  56. IDOS->Close((BPTR)iff->iff_Stream);
  57. }
  58. ELSE_ERROR("Open");
  59.  
  60. IIFF->FreeIFF(iff);
  61. }
  62. ELSE_ERROR("Allocate IFF");
  63.  
  64. INFO_VACATE
  65. return ta;
  66. }
  67.  
  68. void Discard_FontPrefs(void *MemPool, struct TextAttr *ta)
  69. {
  70. INFO_ENTER
  71.  
  72. IExec->FreeVecPooled(MemPool, (STRPTR)ta->ta_Name);
  73. ta->ta_Name = NULL;
  74.  
  75. IExec->FreeVecPooled(MemPool, ta);
  76. ta = NULL;
  77.  
  78. INFO_VACATE
  79. }
  80.  
  81.  
  82. {
  83. if (
  84. ((xn->xn_FixedFont = Retrieve_FontPrefs(xn, 1)) != NULL) &&
  85. (xn->xn_FixedFont->ta_Name != NULL)
  86. )
  87. {
  88. if (
  89. ((xn->xn_PropFont = Retrieve_FontPrefs(xn, 0)) != NULL) &&
  90. (xn->xn_PropFont->ta_Name != NULL)
  91. )
  92. {
  93. if ((xn->xn_FixedFontString = IUtility->ASPrintf("%s/%lu", xn->xn_FixedFont->ta_Name
  94. , (xn->xn_FixedFont->ta_YSize - 2))))
  95. {
  96. .
  97. .
  98. .
  99. .
  100. .
  101. .
  102.  
  103. IExec->FreeVec(xn->xn_FixedFontString);
  104. xn->xn_FixedFontString = NULL;
  105. }
  106.  
  107. Discard_FontPrefs(xn->xn_MemPool, xn->xn_PropFont);
  108. }
  109. ELSE_ERROR("Retrieve FontPrefs (Proportional)");
  110.  
  111. Discard_FontPrefs(xn->xn_MemPool, xn->xn_FixedFont);
  112. }
  113. ELSE_ERROR("Retrieve FontPrefs (Fixed)");
  114.  
  115. }

Maybe this can be of help to you?

OldFart

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Different size labels

@walkero

The problem with IA_Font (a general tag defined at the Image Class level) is that different image subclasses may use it differently. The original documentation did not specify clearly whether the tag should take a struct TextAttr pointer, or a struct TextFont pointer. So you can come across both uses in the wild.

The Label Image class expects a struct TextAttr pointer in IA_Font, and this is what I use in my ToolBar Gadget class. But you can use LABEL_DrawInfo instead if you have the struct DrawInfo pointer. You just have to make sure that they precede the LABEL_Text tag, otherwise the font will not be set for the label.

As for the font size adjustment: I just obtain the screen font (struct TextAttr) pointer from the struct Screen and decrease the size by the required number of pixels, i.e something like

mySize = scr->Font->ta_YSize - 2;

Hope this helps.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: Different size labels

Thank you both for the explanation. I will try these out and let you know how it goes.

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Re: Different size labels

If LABEL_Font does not exist, then IA_Font is probably the way to go.

LABEL_DrawInfo is not a solution. You can get a DrawInfo from the screen using GetScreenDrawInfo(), you should not try to build your own. But what you get is read-only, you should not poke different values into it.

Reading the prefs files should not be necessary. You can get the screen font from Screen->Font (struct TextAttr) or Screen->RastPort.Font (struct TextFont).

The fixed-width system font can be read from GfxBase->DefaultFont or from the Font field of a freshly initialized RastPort. (Both point to a struct TextFont).

And BTW, the current prefs settings should be read from Env: not from Envarc:

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Different size labels

@walkero

LABEL_DrawInfo is not a solution.

It should be, according to the label.image autodoc. (Never tried myself, though: I always use IA_Font with label.image.) I assume the font information for the label text is taken from drawInfo->dri_Font, which is a struct TextFont pointer.

You can get the screen font from Screen->Font (struct TextAttr) or Screen->RastPort.Font (struct TextFont).

For the sake of completeness, you can also query SA_Font via IIntuition->GetScreenAttr().

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Re: Different size labels

It should be, according to the label.image autodoc.

This is the text from the autodocs:

This is also used to get
default font information. If you do not use IA_Font to specify
fonts then you must pass the screen DrawInfo before you give
the IA_Data/LABEL_Text tag.

It clearly says that DrawInfo is required for the label to know the correct default (a.k.a. screen) font.

If you want a custom font, you have to use IA_Font to override the default.

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Different size labels

@thomas

You're right of course - for a moment I forgot what Walkero was after (i.e. setting a smaller version of the screen font, not the screen font itself).

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

Log in or register to post comments