2 Copyright © 1995-2007, 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
)
44 Write text to the rastport at the current position.
45 The current position is updated to a position after the text.
49 string - string to print
50 count - number of characters to print
65 29-10-95 digulla automatically created from
66 graphics_lib.fd and clib/graphics_protos.h
68 *****************************************************************************/
74 struct ColorTextFont
*ctf
= (struct ColorTextFont
*)rp
->Font
;
78 antialias
= (ctf
->ctf_TF
.tf_Style
& FSF_COLORFONT
) &&
79 ((ctf
->ctf_Flags
& CT_COLORMASK
) == CT_ANTIALIAS
) &&
80 (GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
) >= 15);
82 colorfont
= (ctf
->ctf_TF
.tf_Style
& FSF_COLORFONT
) &&
83 (((ctf
->ctf_Flags
& CT_COLORMASK
) == CT_COLORFONT
) || ((ctf
->ctf_Flags
& CT_COLORMASK
) == CT_GREYFONT
));
87 BltTemplateAlphaBasedText(rp
, string
, count
, GfxBase
);
91 ColorFontBasedText(rp
, string
, count
, GfxBase
);
93 else if ((rp
->DrawMode
& INVERSVID
) ||
94 (rp
->AlgoStyle
& (FSF_BOLD
| FSF_ITALIC
| FSF_UNDERLINED
)))
96 BltTemplateBasedText(rp
, string
, count
, GfxBase
);
100 driver_Text (rp
, string
, count
, GfxBase
);
108 /***************************************************************************/
110 void BltTemplateBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
111 struct GfxBase
*GfxBase
)
113 struct TextExtent te
;
115 WORD raswidth
, raswidth16
, raswidth_bpr
, rasheight
, x
, y
, gx
;
117 BOOL is_bold
, is_italic
;
119 TextExtent(rp
, text
, len
, &te
);
121 raswidth
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
122 rasheight
= te
.te_Extent
.MaxY
- te
.te_Extent
.MinY
+ 1;
124 raswidth16
= (raswidth
+ 15) & ~15;
125 raswidth_bpr
= raswidth16
/ 8;
127 if ((raster
= AllocRaster(raswidth
, rasheight
)))
129 memset(raster
, 0, RASSIZE(raswidth
, rasheight
));
133 x
= -te
.te_Extent
.MinX
;
135 is_bold
= (rp
->AlgoStyle
& FSF_BOLD
) != 0;
136 is_italic
= (rp
->AlgoStyle
& FSF_ITALIC
) != 0;
143 UWORD glyphwidth
, glyphpos
, bold
;
149 if (c
< tf
->tf_LoChar
|| c
> tf
->tf_HiChar
)
151 idx
= NUMCHARS(tf
) - 1;
155 idx
= c
- tf
->tf_LoChar
;
158 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[idx
];
160 glyphwidth
= charloc
& 0xFFFF;
161 glyphpos
= charloc
>> 16;
165 x
+= ((WORD
*)tf
->tf_CharKern
)[idx
];
169 for(bold
= 0; bold
<= is_bold
; bold
++)
172 WORD italicshift
, italiccheck
= 0;
176 italiccheck
= tf
->tf_Baseline
;
177 italicshift
= italiccheck
/ 2;
184 wx
= x
+ italicshift
+ (bold
? tf
->tf_BoldSmear
: 0);
186 glyphdata
= ((UBYTE
*)tf
->tf_CharData
) + glyphpos
/ 8;
187 dst
= raster
+ wx
/ 8;
189 for(y
= 0; y
< rasheight
; y
++)
191 UBYTE
*glyphdatax
= glyphdata
;
195 srcmask
= 0x80 >> (glyphpos
& 7);
196 dstmask
= 0x80 >> (wx
& 7);
198 srcdata
= *glyphdatax
;
200 for(gx
= 0; gx
< glyphwidth
; gx
++)
202 if (srcdata
& srcmask
)
221 srcdata
=*glyphdatax
;
228 } /* for(gx = 0; gx < glyphwidth; gx++) */
230 glyphdata
+= tf
->tf_Modulo
;
241 if ((wx
& 7) == 7) dst
--;
246 } /* for(y = 0; y < rasheight; y++) */
248 } /* for(bold = 0; bold < ((rp->AlgoStyle & FSF_BOLD) ? 2 : 1); bold++) */
250 if (tf
->tf_CharSpace
)
252 x
+= ((WORD
*)tf
->tf_CharSpace
)[idx
];
263 if (rp
->AlgoStyle
& FSF_UNDERLINED
)
266 ULONG prev_word
, act_word
= 0, next_word
, word
;
270 underline
= rp
->TxBaseline
+ 1;
271 if (underline
< rasheight
- 1) underline
++;
273 if (underline
< rasheight
)
275 dst
= raster
+ underline
* (LONG
)raswidth_bpr
;
276 next_word
= *(UWORD
*)dst
;
278 next_word
= AROS_WORD2BE(next_word
);
280 count
= raswidth16
/ 16;
284 prev_word
= act_word
;
285 act_word
= next_word
;
288 next_word
= ((UWORD
*)dst
)[1];
291 next_word
= AROS_WORD2BE(next_word
);
298 word
= ((act_word
<< 1) & 0xFFFF) + (next_word
>> 15);
299 word
|= (act_word
>> 1) + ((prev_word
<< 15) & 0xFFFF);
302 word
= 0xFFFF &~ word
;
304 word
= AROS_BE2WORD(word
);
307 *(UWORD
*)dst
= word
;
310 } /* while(count--) */
312 } /* if (underline < rasheight) */
314 } /* if (rp->AlgoStyle & FSF_UNDERLINED) */
320 rp
->cp_x
+ te
.te_Extent
.MinX
,
321 rp
->cp_y
- rp
->TxBaseline
,
325 FreeRaster(raster
, raswidth
, rasheight
);
327 } /* if ((raster = AllocRaster(raswidth, rasheight))) */
329 Move(rp
, rp
->cp_x
+ te
.te_Width
, rp
->cp_y
);
333 /***************************************************************************/
335 static struct Library
*CyberGfxBase
= NULL
;
337 static void AROS_SET_LIBFUNC(CGFX_Expunge
, LIBBASETYPE
, LIBBASE
)
339 if (CyberGfxBase
!= NULL
)
341 CloseLibrary(CyberGfxBase
);
347 /***************************************************************************/
349 void BltTemplateAlphaBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
350 struct GfxBase
*GfxBase
)
352 struct TextExtent te
;
354 WORD raswidth
, raswidth_bpr
, rasheight
, x
, y
, gx
;
356 BOOL is_bold
, is_italic
;
360 CyberGfxBase
= OpenLibrary("cybergraphics.library", 0);
361 if (!CyberGfxBase
) return;
364 TextExtent(rp
, text
, len
, &te
);
366 raswidth
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
367 rasheight
= te
.te_Extent
.MaxY
- te
.te_Extent
.MinY
+ 1;
369 raswidth_bpr
= raswidth
;
371 if ((raster
= AllocVec(raswidth
* rasheight
, MEMF_CLEAR
)))
375 x
= -te
.te_Extent
.MinX
;
377 is_bold
= (rp
->AlgoStyle
& FSF_BOLD
) != 0;
378 is_italic
= (rp
->AlgoStyle
& FSF_ITALIC
) != 0;
385 UWORD glyphwidth
, glyphpos
, bold
;
389 if (c
< tf
->tf_LoChar
|| c
> tf
->tf_HiChar
)
391 idx
= NUMCHARS(tf
) - 1;
395 idx
= c
- tf
->tf_LoChar
;
398 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[idx
];
400 glyphwidth
= charloc
& 0xFFFF;
401 glyphpos
= charloc
>> 16;
405 x
+= ((WORD
*)tf
->tf_CharKern
)[idx
];
409 for(bold
= 0; bold
<= is_bold
; bold
++)
412 WORD italicshift
, italiccheck
= 0;
416 italiccheck
= tf
->tf_Baseline
;
417 italicshift
= italiccheck
/ 2;
424 wx
= x
+ italicshift
+ (bold
? tf
->tf_BoldSmear
: 0);
426 glyphdata
= ((UBYTE
*)((struct ColorTextFont
*)tf
)->ctf_CharData
[0]) + glyphpos
;
429 for(y
= 0; y
< rasheight
; y
++)
431 UBYTE
*glyphdatax
= glyphdata
;
434 for(gx
= 0; gx
< glyphwidth
; gx
++)
438 old
+= *glyphdatax
++;
439 if (old
> 255) old
= 255;
443 glyphdata
+= tf
->tf_Modulo
* 8;
456 } /* for(y = 0; y < rasheight; y++) */
458 } /* for(bold = 0; bold < ((rp->AlgoStyle & FSF_BOLD) ? 2 : 1); bold++) */
460 if (tf
->tf_CharSpace
)
462 x
+= ((WORD
*)tf
->tf_CharSpace
)[idx
];
473 if (rp
->AlgoStyle
& FSF_UNDERLINED
)
476 UBYTE prev_byte
, act_byte
= 0, next_byte
;
480 underline
= rp
->TxBaseline
+ 1;
481 if (underline
< rasheight
- 1) underline
++;
483 if (underline
< rasheight
)
485 dst
= raster
+ underline
* (LONG
)raswidth_bpr
;
492 prev_byte
= act_byte
;
493 act_byte
= next_byte
;
503 *dst
++ = (act_byte
|| (!prev_byte
&& !next_byte
)) ? 255 : 0;
505 } /* while(count--) */
507 } /* if (underline < rasheight) */
509 } /* if (rp->AlgoStyle & FSF_UNDERLINED) */
511 BltTemplateAlpha(raster
,
515 rp
->cp_x
+ te
.te_Extent
.MinX
,
516 rp
->cp_y
- rp
->TxBaseline
,
522 } /* if ((raster = AllocVec(raswidth * rasheight, MEMF_CLEAR))) */
524 Move(rp
, rp
->cp_x
+ te
.te_Width
, rp
->cp_y
);
528 /***************************************************************************/
530 void ColorFontBasedText(struct RastPort
*rp
, CONST_STRPTR text
, ULONG len
,
531 struct GfxBase
*GfxBase
)
533 struct TextExtent te
;
535 WORD raswidth
, raswidth_bpr
, rasheight
, x
, y
, gx
;
536 UBYTE
*raster
, *chunky
;
537 BOOL is_bold
, is_italic
;
540 if (!ExtendFont(tf
, NULL
)) return;
542 chunky
= ((struct TextFontExtension_intern
*)(tf
->tf_Extension
))->hash
->chunky_colorfont
;
544 TextExtent(rp
, text
, len
, &te
);
546 if ((rp
->DrawMode
& ~INVERSVID
) == JAM2
)
548 ULONG old_drmd
= GetDrMd(rp
);
550 SetDrMd(rp
, old_drmd
^ INVERSVID
);
551 RectFill(rp
, rp
->cp_x
+ te
.te_Extent
.MinX
,
552 rp
->cp_y
+ te
.te_Extent
.MinY
,
553 rp
->cp_x
+ te
.te_Extent
.MaxX
,
554 rp
->cp_y
+ te
.te_Extent
.MaxY
);
555 SetDrMd(rp
, old_drmd
);
559 raswidth
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
560 rasheight
= te
.te_Extent
.MaxY
- te
.te_Extent
.MinY
+ 1;
562 raswidth_bpr
= raswidth
;
564 if ((raster
= AllocVec(raswidth
* rasheight
, MEMF_CLEAR
)))
566 x
= -te
.te_Extent
.MinX
;
568 is_bold
= (rp
->AlgoStyle
& FSF_BOLD
) != 0;
569 is_italic
= (rp
->AlgoStyle
& FSF_ITALIC
) != 0;
576 UWORD glyphwidth
, glyphpos
, bold
;
580 if (c
< tf
->tf_LoChar
|| c
> tf
->tf_HiChar
)
582 idx
= NUMCHARS(tf
) - 1;
586 idx
= c
- tf
->tf_LoChar
;
589 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[idx
];
591 glyphwidth
= charloc
& 0xFFFF;
592 glyphpos
= charloc
>> 16;
596 x
+= ((WORD
*)tf
->tf_CharKern
)[idx
];
600 for(bold
= 0; bold
<= is_bold
; bold
++)
603 WORD italicshift
, italiccheck
= 0;
607 italiccheck
= tf
->tf_Baseline
;
608 italicshift
= italiccheck
/ 2;
615 wx
= x
+ italicshift
+ (bold
? tf
->tf_BoldSmear
: 0);
617 glyphdata
= chunky
+ glyphpos
;
620 for(y
= 0; y
< rasheight
; y
++)
622 UBYTE
*glyphdatax
= glyphdata
;
625 for(gx
= 0; gx
< glyphwidth
; gx
++)
627 UBYTE p
= *glyphdatax
++;
629 if (p
|| !bold
) *dstx
= p
;
634 glyphdata
+= tf
->tf_Modulo
* 8;
647 } /* for(y = 0; y < rasheight; y++) */
649 } /* for(bold = 0; bold < ((rp->AlgoStyle & FSF_BOLD) ? 2 : 1); bold++) */
651 if (tf
->tf_CharSpace
)
653 x
+= ((WORD
*)tf
->tf_CharSpace
)[idx
];
665 if (rp
->AlgoStyle
& FSF_UNDERLINED
)
668 UBYTE prev_byte
, act_byte
= 0, next_byte
;
672 underline
= rp
->TxBaseline
+ 1;
673 if (underline
< rasheight
- 1) underline
++;
675 if (underline
< rasheight
)
677 dst
= raster
+ underline
* (LONG
)raswidth_bpr
;
684 prev_byte
= act_byte
;
685 act_byte
= next_byte
;
695 *dst
++ = (act_byte
|| (!prev_byte
&& !next_byte
)) ? 255 : 0;
697 } /* while(count--) */
699 } /* if (underline < rasheight) */
701 } /* if (rp->AlgoStyle & FSF_UNDERLINED) */
706 HIDDT_PixelLUT pixlut
;
707 HIDDT_Pixel pixtab
[256];
709 pixlut
.entries
= AROS_PALETTE_SIZE
;
710 pixlut
.pixels
= IS_HIDD_BM(rp
->BitMap
) ? HIDD_BM_PIXTAB(rp
->BitMap
) : NULL
;
712 if ((rp
->Flags
& RPF_REMAP_COLORFONTS
) &&
713 (CTF(tf
)->ctf_ColorFontColors
) &&
714 ((CTF(tf
)->ctf_Flags
& CT_COLORMASK
) != CT_GREYFONT
) && /* <-- FIX/CHECK/SUPPORT CT_GREYFONT) */
715 IS_HIDD_BM(rp
->BitMap
) &&
716 (GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
) > 8))
718 UWORD
*colortable
= CTF(tf
)->ctf_ColorFontColors
->cfc_ColorTable
;
721 for(i
= 0; i
< CTF(tf
)->ctf_ColorFontColors
->cfc_Count
; i
++)
723 UWORD rgb12
= *colortable
++;
726 col
.red
= ((rgb12
>> 8) & 0x0F) * 0x1111;
727 col
.green
= ((rgb12
>> 4) & 0x0F) * 0x1111;
728 col
.blue
= ((rgb12
>> 0) & 0x0F) * 0x1111;
730 pixtab
[i
] = HIDD_BM_MapColor(HIDD_BM_OBJ(rp
->BitMap
), &col
);
733 pixlut
.pixels
= pixtab
;
736 write_transp_pixels_8(rp
, raster
,raswidth_bpr
,
737 rp
->cp_x
+ te
.te_Extent
.MinX
,
738 rp
->cp_y
- rp
->TxBaseline
,
739 rp
->cp_x
+ te
.te_Extent
.MinX
+ raswidth
- 1,
740 rp
->cp_y
- rp
->TxBaseline
+ rasheight
- 1,
741 &pixlut
, 0, TRUE
, GfxBase
);
747 } /* if ((raster = AllocVec(raswidth * rasheight, MEMF_CLEAR))) */
749 Move(rp
, rp
->cp_x
+ te
.te_Width
, rp
->cp_y
);