ref: 488ad626470fd67f028be2b04d515732ebcb9b5c
parent: d2b67d2f95df97111977bb07639afe61b34d9ea2
author: Noam Preil <noam@pixelhero.dev>
date: Fri Apr 8 20:20:28 EDT 2022
gs: implement RGB color support
--- a/op.c
+++ b/op.c
@@ -394,7 +394,12 @@
static int
ccolour(Op *op, Page *p)
{
- USED(op, p);
+ ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;
+ u32int *color = op->flags & Nonstroking ? &p->GSactive->NSC : &p->GSactive->SC;
+ if(c == DeviceRGB){
+ *color = ((u8int)(255 * arrayget(p->stack, 0)->num.d)) << 24 | ((u8int)(255 * arrayget(p->stack, 1)->num.d)) << 16 | ((u8int)(255 * arrayget(p->stack, 2)->num.d)) << 8 | 0xff;
+ return 1;
+ }
return 0;
}
@@ -404,7 +409,6 @@
ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;
if(c < 3)
return ccolour(op, p);
- USED(op, p);
return 0;
}
@@ -752,6 +756,7 @@
{
double Tfs = p->GSactive->Font.size;
double Trm[6];
+ Memimage *ink;
double tx;
int i;
/* Text rendering matrix converts coordinates from font space to device space */
@@ -774,8 +779,18 @@
werrstr("tchar: failed to write character: %r");
return 0;
}
- if(p->buf.b != nil)
- memimagestring(p->image, Pt(Trm[4], Trm[5]), memblack, Pt(0,0), getmemdefont(), (char*)p->buf.b + oend);
+ if(p->buf.b != nil){
+ ink = allocmemimage(Rect(0,0,1,1),RGB24);
+ if(ink == nil){
+ werrstr("failed to allocate ink");
+ return 0;
+ }
+ ink->flags |= Frepl;
+ ink->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
+ memfillcolor(ink, p->GSactive->NSC);
+ memimagestring(p->image, Pt(Trm[4], Trm[5]), ink, Pt(0,0), getmemdefont(), (char*)p->buf.b + oend);
+ freememimage(ink);
+ }
tx = glyphspacing(p, c);
mattrans(p->TS.Tm, tx, 0, p->TS.Tm);
p->TS.x = Trm[4] + tx;