To avoid bothering you further, I've decided to implement all the corrections and optimizations myself. Here is the final version of the library, ready for publication:
Code:
// Custom Text Formatting Library v1.00 by Tyann & Komame
ICON buffer 89504E470D0A1A0A0000000D494844520000014B0000001F010000000046A4D2660000000274524E5300010194FDAE0000001E494441547801EDCA310100000C0220FBA75C9359C10070935F9DAAAAAA5ADAB10D75F21D64EC0000000049454E44AE426082;
EXPORT ATEXTSIZE(s,p,a)
BEGIN
LOCAL h,l,f;
{'l','h'}:=TEXTSIZE(s,p);
IF BITAND(a,8) THEN
l:=l+CEILING(h/3);
END;
IF BITAND(a,16) THEN
l:=l+1;f:=1;
END;
IF BITAND(a,32) THEN
l:=l+1-f;h:=h+1;
END;
{l,h};
END;
EXPORT ATEXTOUT_P(...l)
BEGIN
LOCAL d,f;
IF TYPE(l(2))≠8 THEN l(−2):=G0;END;
d:=SIZE(l);
IF d<7 THEN
f:=STRING(l);
f:="TEXTOUT_P("+SUPPRESS(f,{1,DIM(f)});
RETURN EXPR(f);
END;
IF d<10 THEN
l:=CONCAT(l,SUB({0,320,−1},d-6,3));
ELSE
IF d>10 THEN Err(0);END;
IF l(10)<0 THEN Err(2);END;
END;
IF l(2)≠8 THEN Err(2);END;
atextout(l(1),l(2),l(3),l(4),l(5),l(6),l(7),l(8),l(9),l(10));
END;
atextout(s,g,x,y,p,c,a,t,l,f)
BEGIN
LOCAL i,j,k,fi,fr;
LOCAL ii,h;
IF 63<a OR a<0 OR 255<t OR t<0 THEN
Err(2);
END;
fr:=(f≥0); t:=255-t;
{'k','h'}:=ATEXTSIZE(s,p,a);
l:=MIN(l,k);
BLIT_P("buffer",11,0,g,x,y-3,x+l+1,y+h+4);
IF fr THEN
RECT_P("buffer",11,3,11+k+1,3+h-1,f,f);
END;
i:=1;
REPEAT
IF i==16 THEN
TEXTOUT_P(s,"buffer",11,3,p,c,l);
END;
IF BITAND(a,i) THEN
CASE
if i==1 then //barré / strikethrough
j:=CEILING(h-p-2);
LINE_P("buffer",11,j,11+l,j,c);
end;
if i==2 then //sous ligné / underline
LINE_P("buffer",11,h-2+3,11+l,h-2+3,c);
end;
if i==4 then //encadré / frame
RECT_P("buffer",11,2,11+l-1,h-1+3,c,{0,255});
end;
if i==8 then //italique / italic
j:=11;
FOR ii:=h+3 DOWNTO -2 STEP 3 DO
BLIT_P("buffer",j,ii,"buffer",11,ii,11+l,ii+3);
j:=j-1;
END;
fi:=1;
end
if BITAND(a,16) then //gras / bold
TEXTOUT_P(s,"buffer",12,3,p,c,l);
end;
if BITAND(a,32) then //relief
TEXTOUT_P(s,"buffer",12,4,p,c,l);
end;
END;//CASE
END;//BITAND
i:=i*2;
UNTIL i==64;
IF fi THEN
j:=11;
FOR ii:=h+3 DOWNTO -2 STEP 3 DO
BLIT_P(g,x,y+ii-3,"buffer",j,ii,j+l,ii+3,{0,255},t);
j:=j-1;
END;
ELSE
BLIT_P(g,x,y-3,"buffer",11,0,l+11,h+6,{0,255},t);
END;
END;
Err(n)
BEGIN
LOCAL l:={};
CASE
if n==0 then EXPR(":"); end;
if n==1 then UPPER(1); end;
if n==2 then l(1); end;
if n==3 then l+{1,2}; end;
if n==4 then CROSS([1],[1,1]);end;
END;
END;