Roxen.git/server/font_handlers/ttf.pike:1:
// This file is part of Roxen WebServer.
// Copyright © 1996 - 2000, Roxen IS.
#if !constant(Image.FreeType.Face)
#if constant(has_Image_TTF)
#include <config.h>
- constant cvs_version = "$Id: ttf.pike,v 1.15 2003/05/05 14:31:08 jonasw Exp $";
+ constant cvs_version = "$Id: ttf.pike,v 1.16 2003/11/05 17:44:09 jonasw Exp $";
constant name = "TTF fonts";
constant doc = "True Type font loader. Uses freetype to render text.";
constant scalable = 1;
inherit FontHandler;
static mapping ttf_font_names_cache;
static string trimttfname( string n )
Roxen.git/server/font_handlers/ttf.pike:111: Inside #if !constant(Image.FreeType.Face)
feed(s)->drain();
}):what));
}
// FIXME: Handle x_spacing
Image.Image write( string ... what )
{
if( !sizeof( what ) )
return Image.Image( 1,height() );
+ int oversample = roxen->query("font_oversampling");
+
// nbsp -> ""
what = map( (array(string))what, replace, " ", "" );
// cannot write "" with Image.TTF.
what = replace( what, "", " " );
array(Image.Image) res = map( what, real_write );
- Image.Image rr = Image.Image( max(0,@res->xsize()),
- (int)abs(`+(0,0,@res[..sizeof(res)-2]->ysize())*y_spacing)+res[-1]->ysize() );
+ int image_width = max(0, @res->xsize());
+ int image_height =
+ (int)abs(`+(0, 0, @res[..sizeof(res) - 2]->ysize()) * y_spacing) +
+ res[-1]->ysize();
+ int y_add = 0;
+ if (oversample) {
+ // Make sure image dimensions are a multiple of 2. If height is odd
+ // we'll offset the text baseline one pixel to get the extra line at
+ // the top of the image.
+ image_width = (image_width + 1) & 0xFFFFFFFE;
+ y_add = (image_height & 1);
+ image_height = (image_height + 1) & 0xFFFFFFFE;
+ }
+ Image.Image rr = Image.Image(image_width, image_height);
float start;
if( y_spacing < 0 )
start = (float)rr->ysize()-res[0]->ysize();
-
+ start += (float) y_add;
foreach( res, object r )
{
if( j_right )
rr->paste_alpha_color( r, 255,255,255, rr->xsize()-r->xsize(), (int)start );
else if( j_center )
rr->paste_alpha_color( r, 255,255,255,(rr->xsize()-r->xsize())/2, (int)start );
else
rr->paste_alpha_color( r, 255,255,255, 0, (int)start );
start += r->ysize()*y_spacing;
Roxen.git/server/font_handlers/ttf.pike:148: Inside #if !constant(Image.FreeType.Face)
object r2 = Image.Image( rr->xsize()+2, rr->ysize() );
object r3 = rr*0.3;
for( int i = 0; i<2; i++ )
for( int j = 0; j<2; j++ )
r2->paste_alpha_color( r3, 255, 255, 255, i, j );
rr = r2->paste_alpha_color( rr, 255,255,255, 1,1 );
}
rr->setcolor( 0,0,0 );
if( fake_italic )
rr = rr->skewx( -(rr->ysize()/3) );
- if( roxen->query("font_oversampling") )
+ if (oversample)
return rr->scale(0.5);
else
return rr;
}
array text_extents( string what )
{
Image.Image o = write( what );
return ({ o->xsize(), o->ysize() });
}