2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Graphics function Text()
8 #include "graphics_intern.h"
9 #include <graphics/rastport.h>
11 #define __CYBERGRAPHICS_NOLIBBASE__
12 #include <proto/cybergraphics.h>
13 #include <aros/macros.h>
14 #include <aros/debug.h>
16 #include "gfxfuncsupport.h"
18 void BltTemplateBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
19 struct GfxBase
*GfxBase
);
21 void BltTemplateAlphaBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
22 struct GfxBase
*GfxBase
);
24 void ColorFontBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
25 struct GfxBase
*GfxBase
);
27 /*****************************************************************************
30 #include <graphics/rastport.h>
31 #include <proto/graphics.h>
36 AROS_LHA(struct RastPort
*, rp
, A1
),
37 AROS_LHA(CONST_STRPTR
, string
, A0
),
38 AROS_LHA(ULONG
, count
, D0
),
41 struct GfxBase
*, GfxBase
, 10, Graphics
)
60 29-10-95 digulla automatically created from
61 graphics_lib.fd and clib/graphics_protos.h
63 *****************************************************************************/
66 AROS_LIBBASE_EXT_DECL(struct GfxBase
*,GfxBase
)
70 struct ColorTextFont
*ctf
= (struct ColorTextFont
*)rp
->Font
;
74 antialias
= (ctf
->ctf_TF
.tf_Style
& FSF_COLORFONT
) &&
75 ((ctf
->ctf_Flags
& CT_COLORMASK
) == CT_ANTIALIAS
) &&
76 (GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
) >= 15);
78 colorfont
= (ctf
->ctf_TF
.tf_Style
& FSF_COLORFONT
) &&
79 (((ctf
->ctf_Flags
& CT_COLORMASK
) == CT_COLORFONT
) || ((ctf
->ctf_Flags
& CT_COLORMASK
) == CT_GREYFONT
));
83 BltTemplateAlphaBasedText(rp
, string
, count
, GfxBase
);
87 ColorFontBasedText(rp
, string
, count
, GfxBase
);
89 else if ((rp
->DrawMode
& INVERSVID
) ||
90 (rp
->AlgoStyle
& (FSF_BOLD
| FSF_ITALIC
| FSF_UNDERLINED
)))
92 BltTemplateBasedText(rp
, string
, count
, GfxBase
);
96 driver_Text (rp
, string
, count
, GfxBase
);
104 /***************************************************************************/
106 void BltTemplateBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
107 struct GfxBase
*GfxBase
)
109 struct TextExtent te
;
111 WORD raswidth
, raswidth16
, raswidth_bpr
, rasheight
, x
, y
, gx
;
113 BOOL is_bold
, is_italic
;
115 TextExtent(rp
, text
, len
, &te
);
117 raswidth
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
118 rasheight
= te
.te_Extent
.MaxY
- te
.te_Extent
.MinY
+ 1;
120 raswidth16
= (raswidth
+ 15) & ~15;
121 raswidth_bpr
= raswidth16
/ 8;
123 if ((raster
= AllocRaster(raswidth
, rasheight
)))
125 memset(raster
, 0, RASSIZE(raswidth
, rasheight
));
129 x
= -te
.te_Extent
.MinX
;
131 is_bold
= (rp
->AlgoStyle
& FSF_BOLD
) != 0;
132 is_italic
= (rp
->AlgoStyle
& FSF_ITALIC
) != 0;
139 UWORD glyphwidth
, glyphpos
, bold
;
145 if (c
< tf
->tf_LoChar
|| c
> tf
->tf_HiChar
)
147 idx
= NUMCHARS(tf
) - 1;
151 idx
= c
- tf
->tf_LoChar
;
154 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[idx
];
156 glyphwidth
= charloc
& 0xFFFF;
157 glyphpos
= charloc
>> 16;
161 x
+= ((WORD
*)tf
->tf_CharKern
)[idx
];
165 for(bold
= 0; bold
<= is_bold
; bold
++)
168 WORD italicshift
, italiccheck
= 0;
172 italiccheck
= tf
->tf_Baseline
;
173 italicshift
= italiccheck
/ 2;
180 wx
= x
+ italicshift
+ (bold
? tf
->tf_BoldSmear
: 0);
182 glyphdata
= ((UBYTE
*)tf
->tf_CharData
) + glyphpos
/ 8;
183 dst
= raster
+ wx
/ 8;
185 for(y
= 0; y
< rasheight
; y
++)
187 UBYTE
*glyphdatax
= glyphdata
;
191 srcmask
= 0x80 >> (glyphpos
& 7);
192 dstmask
= 0x80 >> (wx
& 7);
194 srcdata
= *glyphdatax
;
196 for(gx
= 0; gx
< glyphwidth
; gx
++)
198 if (srcdata
& srcmask
)
217 srcdata
=*glyphdatax
;
224 } /* for(gx = 0; gx < glyphwidth; gx++) */
226 glyphdata
+= tf
->tf_Modulo
;
237 if ((wx
& 7) == 7) dst
--;
242 } /* for(y = 0; y < rasheight; y++) */
244 } /* for(bold = 0; bold < ((rp->AlgoStyle & FSF_BOLD) ? 2 : 1); bold++) */
246 if (tf
->tf_CharSpace
)
248 x
+= ((WORD
*)tf
->tf_CharSpace
)[idx
];
259 if (rp
->AlgoStyle
& FSF_UNDERLINED
)
262 ULONG prev_word
, act_word
= 0, next_word
, word
;
266 underline
= rp
->TxBaseline
+ 1;
267 if (underline
< rasheight
- 1) underline
++;
269 if (underline
< rasheight
)
271 dst
= raster
+ underline
* (LONG
)raswidth_bpr
;
272 next_word
= *(UWORD
*)dst
;
274 next_word
= AROS_WORD2BE(next_word
);
276 count
= raswidth16
/ 16;
280 prev_word
= act_word
;
281 act_word
= next_word
;
284 next_word
= ((UWORD
*)dst
)[1];
287 next_word
= AROS_WORD2BE(next_word
);
294 word
= ((act_word
<< 1) & 0xFFFF) + (next_word
>> 15);
295 word
|= (act_word
>> 1) + ((prev_word
<< 15) & 0xFFFF);
298 word
= 0xFFFF &~ word
;
300 word
= AROS_BE2WORD(word
);
303 *(UWORD
*)dst
= word
;
306 } /* while(count--) */
308 } /* if (underline < rasheight) */
310 } /* if (rp->AlgoStyle & FSF_UNDERLINED) */
316 rp
->cp_x
+ te
.te_Extent
.MinX
,
317 rp
->cp_y
- rp
->TxBaseline
,
321 FreeRaster(raster
, raswidth
, rasheight
);
323 } /* if ((raster = AllocRaster(raswidth, rasheight))) */
325 Move(rp
, rp
->cp_x
+ te
.te_Width
, rp
->cp_y
);
329 /***************************************************************************/
331 static struct Library
*CyberGfxBase
= NULL
;
333 static AROS_SET_LIBFUNC(CGFX_Expunge
, LIBBASETYPE
, LIBBASE
)
335 if (CyberGfxBase
!= NULL
)
337 CloseLibrary(CyberGfxBase
);
343 /***************************************************************************/
345 void BltTemplateAlphaBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
346 struct GfxBase
*GfxBase
)
348 struct TextExtent te
;
350 WORD raswidth
, raswidth_bpr
, rasheight
, x
, y
, gx
;
352 BOOL is_bold
, is_italic
;
356 CyberGfxBase
= OpenLibrary("cybergraphics.library", 0);
357 if (!CyberGfxBase
) return;
360 TextExtent(rp
, text
, len
, &te
);
362 raswidth
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
363 rasheight
= te
.te_Extent
.MaxY
- te
.te_Extent
.MinY
+ 1;
365 raswidth_bpr
= raswidth
;
367 if ((raster
= AllocVec(raswidth
* rasheight
, MEMF_CLEAR
)))
371 x
= -te
.te_Extent
.MinX
;
373 is_bold
= (rp
->AlgoStyle
& FSF_BOLD
) != 0;
374 is_italic
= (rp
->AlgoStyle
& FSF_ITALIC
) != 0;
381 UWORD glyphwidth
, glyphpos
, bold
;
385 if (c
< tf
->tf_LoChar
|| c
> tf
->tf_HiChar
)
387 idx
= NUMCHARS(tf
) - 1;
391 idx
= c
- tf
->tf_LoChar
;
394 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[idx
];
396 glyphwidth
= charloc
& 0xFFFF;
397 glyphpos
= charloc
>> 16;
401 x
+= ((WORD
*)tf
->tf_CharKern
)[idx
];
405 for(bold
= 0; bold
<= is_bold
; bold
++)
408 WORD italicshift
, italiccheck
= 0;
412 italiccheck
= tf
->tf_Baseline
;
413 italicshift
= italiccheck
/ 2;
420 wx
= x
+ italicshift
+ (bold
? tf
->tf_BoldSmear
: 0);
422 glyphdata
= ((UBYTE
*)((struct ColorTextFont
*)tf
)->ctf_CharData
[0]) + glyphpos
;
425 for(y
= 0; y
< rasheight
; y
++)
427 UBYTE
*glyphdatax
= glyphdata
;
430 for(gx
= 0; gx
< glyphwidth
; gx
++)
434 old
+= *glyphdatax
++;
435 if (old
> 255) old
= 255;
439 glyphdata
+= tf
->tf_Modulo
* 8;
452 } /* for(y = 0; y < rasheight; y++) */
454 } /* for(bold = 0; bold < ((rp->AlgoStyle & FSF_BOLD) ? 2 : 1); bold++) */
456 if (tf
->tf_CharSpace
)
458 x
+= ((WORD
*)tf
->tf_CharSpace
)[idx
];
469 if (rp
->AlgoStyle
& FSF_UNDERLINED
)
472 UBYTE prev_byte
, act_byte
= 0, next_byte
;
476 underline
= rp
->TxBaseline
+ 1;
477 if (underline
< rasheight
- 1) underline
++;
479 if (underline
< rasheight
)
481 dst
= raster
+ underline
* (LONG
)raswidth_bpr
;
488 prev_byte
= act_byte
;
489 act_byte
= next_byte
;
499 *dst
++ = (act_byte
|| (!prev_byte
&& !next_byte
)) ? 255 : 0;
501 } /* while(count--) */
503 } /* if (underline < rasheight) */
505 } /* if (rp->AlgoStyle & FSF_UNDERLINED) */
507 BltTemplateAlpha(raster
,
511 rp
->cp_x
+ te
.te_Extent
.MinX
,
512 rp
->cp_y
- rp
->TxBaseline
,
518 } /* if ((raster = AllocVec(raswidth * rasheight, MEMF_CLEAR))) */
520 Move(rp
, rp
->cp_x
+ te
.te_Width
, rp
->cp_y
);
524 /***************************************************************************/
526 void ColorFontBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
527 struct GfxBase
*GfxBase
)
529 struct TextExtent te
;
531 WORD raswidth
, raswidth_bpr
, rasheight
, x
, y
, gx
;
532 UBYTE
*raster
, *chunky
;
533 BOOL is_bold
, is_italic
;
536 if (!ExtendFont(tf
, NULL
)) return;
538 chunky
= TFE_INTERN(tf
->tf_Extension
)->hash
->chunky_colorfont
;
540 TextExtent(rp
, text
, len
, &te
);
542 if ((rp
->DrawMode
& ~INVERSVID
) == JAM2
)
544 ULONG old_drmd
= GetDrMd(rp
);
546 SetDrMd(rp
, old_drmd
^ INVERSVID
);
547 RectFill(rp
, rp
->cp_x
+ te
.te_Extent
.MinX
,
548 rp
->cp_y
+ te
.te_Extent
.MinY
,
549 rp
->cp_x
+ te
.te_Extent
.MaxX
,
550 rp
->cp_y
+ te
.te_Extent
.MaxY
);
551 SetDrMd(rp
, old_drmd
);
555 raswidth
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
556 rasheight
= te
.te_Extent
.MaxY
- te
.te_Extent
.MinY
+ 1;
558 raswidth_bpr
= raswidth
;
560 if ((raster
= AllocVec(raswidth
* rasheight
, MEMF_CLEAR
)))
562 x
= -te
.te_Extent
.MinX
;
564 is_bold
= (rp
->AlgoStyle
& FSF_BOLD
) != 0;
565 is_italic
= (rp
->AlgoStyle
& FSF_ITALIC
) != 0;
572 UWORD glyphwidth
, glyphpos
, bold
;
576 if (c
< tf
->tf_LoChar
|| c
> tf
->tf_HiChar
)
578 idx
= NUMCHARS(tf
) - 1;
582 idx
= c
- tf
->tf_LoChar
;
585 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[idx
];
587 glyphwidth
= charloc
& 0xFFFF;
588 glyphpos
= charloc
>> 16;
592 x
+= ((WORD
*)tf
->tf_CharKern
)[idx
];
596 for(bold
= 0; bold
<= is_bold
; bold
++)
599 WORD italicshift
, italiccheck
= 0;
603 italiccheck
= tf
->tf_Baseline
;
604 italicshift
= italiccheck
/ 2;
611 wx
= x
+ italicshift
+ (bold
? tf
->tf_BoldSmear
: 0);
613 glyphdata
= chunky
+ glyphpos
;
616 for(y
= 0; y
< rasheight
; y
++)
618 UBYTE
*glyphdatax
= glyphdata
;
621 for(gx
= 0; gx
< glyphwidth
; gx
++)
623 UBYTE p
= *glyphdatax
++;
625 if (p
|| !bold
) *dstx
= p
;
630 glyphdata
+= tf
->tf_Modulo
* 8;
643 } /* for(y = 0; y < rasheight; y++) */
645 } /* for(bold = 0; bold < ((rp->AlgoStyle & FSF_BOLD) ? 2 : 1); bold++) */
647 if (tf
->tf_CharSpace
)
649 x
+= ((WORD
*)tf
->tf_CharSpace
)[idx
];
661 if (rp
->AlgoStyle
& FSF_UNDERLINED
)
664 UBYTE prev_byte
, act_byte
= 0, next_byte
;
668 underline
= rp
->TxBaseline
+ 1;
669 if (underline
< rasheight
- 1) underline
++;
671 if (underline
< rasheight
)
673 dst
= raster
+ underline
* (LONG
)raswidth_bpr
;
680 prev_byte
= act_byte
;
681 act_byte
= next_byte
;
691 *dst
++ = (act_byte
|| (!prev_byte
&& !next_byte
)) ? 255 : 0;
693 } /* while(count--) */
695 } /* if (underline < rasheight) */
697 } /* if (rp->AlgoStyle & FSF_UNDERLINED) */
702 HIDDT_PixelLUT pixlut
;
703 HIDDT_Pixel pixtab
[256];
705 pixlut
.entries
= AROS_PALETTE_SIZE
;
706 pixlut
.pixels
= IS_HIDD_BM(rp
->BitMap
) ? HIDD_BM_PIXTAB(rp
->BitMap
) : NULL
;
708 if ((rp
->Flags
& RPF_REMAP_COLORFONTS
) &&
709 (CTF(tf
)->ctf_ColorFontColors
) &&
710 ((CTF(tf
)->ctf_Flags
& CT_COLORMASK
) != CT_GREYFONT
) && /* <-- FIX/CHECK/SUPPORT CT_GREYFONT) */
711 IS_HIDD_BM(rp
->BitMap
) &&
712 (GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
) > 8))
714 UWORD
*colortable
= CTF(tf
)->ctf_ColorFontColors
->cfc_ColorTable
;
717 for(i
= 0; i
< CTF(tf
)->ctf_ColorFontColors
->cfc_Count
; i
++)
719 UWORD rgb12
= *colortable
++;
722 col
.red
= ((rgb12
>> 8) & 0x0F) * 0x1111;
723 col
.green
= ((rgb12
>> 4) & 0x0F) * 0x1111;
724 col
.blue
= ((rgb12
>> 0) & 0x0F) * 0x1111;
726 pixtab
[i
] = HIDD_BM_MapColor(HIDD_BM_OBJ(rp
->BitMap
), &col
);
729 pixlut
.pixels
= pixtab
;
732 write_transp_pixels_8(rp
, raster
,raswidth_bpr
,
733 rp
->cp_x
+ te
.te_Extent
.MinX
,
734 rp
->cp_y
- rp
->TxBaseline
,
735 rp
->cp_x
+ te
.te_Extent
.MinX
+ raswidth
- 1,
736 rp
->cp_y
- rp
->TxBaseline
+ rasheight
- 1,
737 &pixlut
, 0, GfxBase
);
743 } /* if ((raster = AllocVec(raswidth * rasheight, MEMF_CLEAR))) */
745 Move(rp
, rp
->cp_x
+ te
.te_Width
, rp
->cp_y
);