Skip to content

Commit

Permalink
- Font::direction is now double, in degrees, in contrast as it
Browse files Browse the repository at this point in the history
  was before - int, in tenths of a degree.
  • Loading branch information
dk committed Oct 25, 2007
1 parent b639e61 commit 0ac7be9
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Prima/PS/Drawable.pm
Expand Up @@ -952,7 +952,7 @@ sub text_out
$self-> emit("$wmul 1 Z") if $wmul != 1;
$self-> emit("0 0 M");
if ( $self-> {font}-> {direction} != 0) {
my $r = $self-> {font}-> {direction} / 10;
my $r = $self-> {font}-> {direction};
$self-> emit("$r R");
}
my @rb;
Expand Down Expand Up @@ -1559,8 +1559,8 @@ sub get_text_box
$ret[$_] += $self-> {font}-> {descent} for (1,3,5,7,9);
}
if ( $self-> {font}-> {direction} != 0) {
my $s = sin( $self-> {font}-> {direction} / 572.9577951);
my $c = cos( $self-> {font}-> {direction} / 572.9577951);
my $s = sin( $self-> {font}-> {direction} / 57.29577951);
my $c = cos( $self-> {font}-> {direction} / 57.29577951);
my $i;
for ( $i = 0; $i < 10; $i+=2) {
my ( $x, $y) = @ret[$i,$i+1];
Expand Down
2 changes: 1 addition & 1 deletion Types.cls
Expand Up @@ -42,7 +42,7 @@ global %Font {
int width ;
int style ;
int pitch ;
int direction ;
double direction ;
long resolution ;
string name ;
int size ;
Expand Down
4 changes: 2 additions & 2 deletions examples/fontdlg.pl
Expand Up @@ -452,7 +452,7 @@ sub run {
scheme => ss::Axis,
increment => 30,
step => 10,
onChange => sub { $fd = $_[0]-> value * 10; &$re_sample; },
onChange => sub { $fd = $_[0]-> value; &$re_sample; },
);

$csl-> insert( Button =>
Expand Down Expand Up @@ -555,7 +555,7 @@ sub run {
my $name = $font-> name;
my $size = $font-> size;
$fs = $font-> style;
$fd = $font-> direction / 10;
$fd = $font-> direction;
my ( $i, $j);
for ( $i = 0; $i < scalar @fontItems; $i++)
{
Expand Down
16 changes: 8 additions & 8 deletions examples/matrix.pl
Expand Up @@ -49,7 +49,7 @@
my $digitShades = 8; # range 1 - 20
my $textShades = 3; # range 1 - 20
my $shadesDepth = 4; # range 1 - 100
my $xshspeed = 2; # range 1 - 4
my $xshspeed = 0.2; # range 1 - 4
my $basicfsize = 10; # range 6 - 24
my $vlines = 40; # range 10 - 80
my $textToBMRatio = 0.3; # range 0.01 - 0.9
Expand All @@ -65,7 +65,7 @@
my @vlbms = map { int( rand( 3))} 1..$vlines;
my @vlxcol = (( 0) x $vlines);
my @vlbmxcol = (( 0) x $vlines);
my $xshcnt = -1000;
my $xshcnt = -100;
my $xshdir = 1;
my $xcol = 30;
my $yextraspeed = 0;
Expand Down Expand Up @@ -107,16 +107,16 @@ sub efont
$owidth = $owidth * $id * $widefactor;
$owidth = ( $owidth < 1) ? 1 : $owidth;

if ( $xshcnt > 1000) {
$xshdir = -1;
} elsif ( $xshcnt < -1000) {
$xshdir = 50;
if ( $xshcnt > 100) {
$xshdir = -0.1;
} elsif ( $xshcnt < -100) {
$xshdir = 5;
}
$xshcnt += $xshdir * $xshspeed;
$c-> font-> set(
height => $oheight,
width => $owidth,
direction => int(($xshcnt * 0.1 + $id / $maxstep * 60) / 10) * 10
direction => ($xshcnt + $id / $maxstep * 6) / 10,
);
}

Expand Down Expand Up @@ -244,7 +244,7 @@ sub resetfs
ecolor( $c, $cc, $self-> backColor, $x / 30);
my $mp;
if ( $tickerMode) {
$mp = abs( $c-> font-> direction);
$mp = abs( 10 * int( $c-> font-> direction));
if ( $mp < 100) {
$mp = $mp * 10 + $mp / 10;
} else {
Expand Down
5 changes: 3 additions & 2 deletions include/unix/guts.h
Expand Up @@ -181,7 +181,7 @@ typedef struct _FontInfo {
} FontInfo, *PFontInfo;

typedef struct _RotatedFont {
int direction;
double direction;
int first1;
int first2;
int height;
Expand Down Expand Up @@ -1024,7 +1024,8 @@ extern void
prima_update_cursor( Handle self);

extern Bool
prima_update_rotated_fonts( PCachedFont f, const char * text, int len, Bool wide, int direction, PRotatedFont *result);
prima_update_rotated_fonts( PCachedFont f, const char * text, int len, Bool wide, double direction, PRotatedFont *result,
Bool * ok_to_not_rotate);

extern void
prima_free_rotated_entry( PCachedFont f);
Expand Down
4 changes: 2 additions & 2 deletions os2/gp.c
Expand Up @@ -827,7 +827,7 @@ apc_gp_get_text_width ( Handle self, const char* text, int len, Bool addOverhang
}
if ( !GpiQueryTextBox( ps, len, ( char*)text, TXTBOX_COUNT, pt)) apiErr;
if ( var font. direction != 0) {
GRADIENTL g = ( GRADIENTL) { ( long) ( cos( var font. direction / GRAD) * 1000) , ( long) ( sin( var font. direction / GRAD) * 1000)};
GRADIENTL g = ( GRADIENTL) { ( long) ( cos( var font. direction / GRAD) * 10000) , ( long) ( sin( var font. direction / GRAD) * 10000)};
if ( !GpiSetCharAngle( ps, &g)) apiErr;
}
return pt[ TXTBOX_CONCAT]. x + ( addOverhang ? pt[ TXTBOX_BOTTOMLEFT]. x : 0);
Expand Down Expand Up @@ -953,7 +953,7 @@ gp_set_font_extra( Handle self, HPS ps, int fontId, PSIZEF sz, Bool vectored, PF
GRADIENTL g;
if ( !GpiSetCharBox( ps, sz)) apiErr;
if ( font-> direction != 0)
g = ( GRADIENTL) { ( long) ( cos( font-> direction / GRAD) * 1000) , ( long) ( sin( font-> direction / GRAD) * 1000)};
g = ( GRADIENTL) { ( long) ( cos( font-> direction / GRAD) * 10000) , ( long) ( sin( font-> direction / GRAD) * 10000)};
else
g = ( GRADIENTL) { 1, 0};
if ( !GpiSetCharAngle( ps, &g)) apiErr;
Expand Down
6 changes: 2 additions & 4 deletions pod/Prima/Drawable.pod
Expand Up @@ -283,10 +283,8 @@ the consistency of the pitch key.

=item direction

A counter-clockwise rotation angle multiplied by 10.
0 is default, 900 is pi/2, 1800 is pi, etc. If a font
could not be rotated, it is usually substituted
to the one that can.
A counter-clockwise rotation angle - 0 is default, 90 is pi/2, 180 is pi, etc.
If a font could not be rotated, it is usually substituted to the one that can.

=item encoding

Expand Down
27 changes: 21 additions & 6 deletions unix/apc_font.c
Expand Up @@ -965,7 +965,7 @@ dump_font( PFont f)
fprintf( stderr, "width: %d\n", f-> width);
fprintf( stderr, "style: %d\n", f-> style);
fprintf( stderr, "pitch: %d\n", f-> pitch);
fprintf( stderr, "direction: %d\n", f-> direction);
fprintf( stderr, "direction: %g\n", f-> direction);
fprintf( stderr, "name: %s\n", f-> name);
fprintf( stderr, "family: %s\n", f-> family);
fprintf( stderr, "size: %d\n", f-> size);
Expand Down Expand Up @@ -1853,16 +1853,31 @@ apc_menu_set_font( Handle self, PFont font)
}

Bool
prima_update_rotated_fonts( PCachedFont f, const char * text, int len, Bool wide, int direction, PRotatedFont * result)
prima_update_rotated_fonts( PCachedFont f, const char * text, int len, Bool wide, double direction, PRotatedFont * result,
Bool * ok_to_not_rotate)
{
PRotatedFont * pr = &f-> rotated;
PRotatedFont r = nil;
int i;

while ( direction < 0) direction += 3600;
direction %= 3600;
if ( direction == 0)
while ( direction < 0) direction += 360.0;
while ( direction > 360.0) direction -= 360.0;

/* granulate direction */
{
double g;
int x = f-> fs-> max_bounds. width;
int y = f-> fs-> max_bounds. ascent + f-> fs-> max_bounds. descent;
if ( x < y) x = y;
g = fabs(0.785398 - atan2(x+1,x)) * 90.0 / 3.14159265358;
if ( g > 0) direction = floor(direction / g) * g;
}

if ( direction == 0.0) {
if ( ok_to_not_rotate) *ok_to_not_rotate = true;
return false;
}
if ( ok_to_not_rotate) *ok_to_not_rotate = false;

/* finding record for given direction */
while (*pr) {
Expand Down Expand Up @@ -1908,7 +1923,7 @@ prima_update_rotated_fonts( PCachedFont f, const char * text, int len, Bool wide
}
bzero( r-> map, r-> length * sizeof( void*));
}
rad = direction * 3.14159 / 1800.0;
rad = direction * 3.14159265358 / 180.0;
r-> sin. l = ( sin1 = sin( -rad)) * UINT16_PRECISION;
r-> cos. l = ( cos1 = cos( -rad)) * UINT16_PRECISION;
r-> sin2.l = ( sin2 = sin( rad)) * UINT16_PRECISION;
Expand Down
17 changes: 10 additions & 7 deletions unix/apc_graphics.c
Expand Up @@ -1559,7 +1559,7 @@ static Point *
gp_get_text_box( Handle self, const char * text, int len, Bool wide);

static Bool
gp_text_out_rotated( Handle self, const char * text, int x, int y, int len, Bool wide)
gp_text_out_rotated( Handle self, const char * text, int x, int y, int len, Bool wide, Bool * ok_to_not_rotate)
{
DEFXX;
int i;
Expand All @@ -1570,7 +1570,7 @@ gp_text_out_rotated( Handle self, const char * text, int x, int y, int len, Bool
int psx, psy, dsx, dsy;
Fixed rx, ry;

if ( !prima_update_rotated_fonts( XX-> font, text, len, wide, PDrawable( self)-> font. direction, &r))
if ( !prima_update_rotated_fonts( XX-> font, text, len, wide, PDrawable( self)-> font. direction, &r, ok_to_not_rotate))
return false;

for ( i = 0; i < len; i++) {
Expand Down Expand Up @@ -1781,9 +1781,12 @@ apc_gp_text_out( Handle self, const char * text, int x, int y, int len, Bool utf
RANGE2(x,y);

if ( PDrawable( self)-> font. direction != 0) {
Bool ret = gp_text_out_rotated( self, text, x, y, len, utf8);
if ( utf8) free(( char *) text);
return ret;
Bool ok_to_not_rotate = false;
Bool ret = gp_text_out_rotated( self, text, x, y, len, utf8, &ok_to_not_rotate);
if ( !ok_to_not_rotate) {
if ( utf8) free(( char *) text);
return ret;
}
}

if ( !XX-> flags. paint_base_line)
Expand Down Expand Up @@ -2189,8 +2192,8 @@ gp_get_text_box( Handle self, const char * text, int len, Bool wide)

if ( PDrawable( self)-> font. direction != 0) {
int i;
double s = sin( PDrawable( self)-> font. direction / 572.9577951);
double c = cos( PDrawable( self)-> font. direction / 572.9577951);
double s = sin( PDrawable( self)-> font. direction / 57.29577951);
double c = cos( PDrawable( self)-> font. direction / 57.29577951);
for ( i = 0; i < 5; i++) {
double x = pt[i]. x * c - pt[i]. y * s;
double y = pt[i]. x * s + pt[i]. y * c;
Expand Down
10 changes: 5 additions & 5 deletions unix/xft.c
Expand Up @@ -486,7 +486,7 @@ prima_xft_font_pick( Handle self, Font * source, Font * dest, double * size)
if ( f. width != 0)
FcMatrixScale( &mat, ( double) f. width / base_width, 1);
if ( f. direction != 0)
FcMatrixRotate( &mat, cos(f.direction * 3.14159 / 1800.0), sin(f.direction * 3.14159 / 1800.0));
FcMatrixRotate( &mat, cos(f.direction * 3.14159265358 / 180.0), sin(f.direction * 3.14159265358 / 180.0));
FcPatternAddMatrix( request, FC_MATRIX, &mat);
}

Expand Down Expand Up @@ -740,8 +740,8 @@ prima_xft_set_font( Handle self, PFont font)
csi = locale;
XX-> xft_map8 = csi-> map;
if ( PDrawable( self)-> font. direction != 0) {
XX-> xft_font_sin = sin( font-> direction / 572.9577951);
XX-> xft_font_cos = cos( font-> direction / 572.9577951);
XX-> xft_font_sin = sin( font-> direction / 57.29577951);
XX-> xft_font_cos = cos( font-> direction / 57.29577951);
} else {
XX-> xft_font_sin = 0.0;
XX-> xft_font_cos = 1.0;
Expand Down Expand Up @@ -979,8 +979,8 @@ prima_xft_get_text_box( Handle self, const char * text, int len, Bool utf8)

if ( PDrawable( self)-> font. direction != 0) {
int i;
double s = sin( PDrawable( self)-> font. direction / 572.9577951);
double c = cos( PDrawable( self)-> font. direction / 572.9577951);
double s = sin( PDrawable( self)-> font. direction / 57.29577951);
double c = cos( PDrawable( self)-> font. direction / 57.29577951);
for ( i = 0; i < 5; i++) {
double x = pt[i]. x * c - pt[i]. y * s;
double y = pt[i]. x * s + pt[i]. y * c;
Expand Down
4 changes: 2 additions & 2 deletions win32/gp.c
Expand Up @@ -1699,8 +1699,8 @@ apc_gp_get_text_box( Handle self, const char* text, int len, Bool utf8)

if ( var font. direction != 0) {
int i;
float s = sin( var font. direction / ( 10 * GRAD));
float c = cos( var font. direction / ( 10 * GRAD));
float s = sin( var font. direction / GRAD);
float c = cos( var font. direction / GRAD);
for ( i = 0; i < 5; i++) {
float x = pt[i]. x * c - pt[i]. y * s;
float y = pt[i]. x * s + pt[i]. y * c;
Expand Down
6 changes: 3 additions & 3 deletions win32/stock.c
Expand Up @@ -662,7 +662,7 @@ font_logfont2font( LOGFONT * lf, Font * f, Point * res)
f-> height = tm. tmHeight;
f-> size = ( f-> height - tm. tmInternalLeading) * 72.0 / res-> y + 0.5;
f-> width = lf-> lfWidth;
f-> direction = lf-> lfEscapement;
f-> direction = lf-> lfEscapement * 10;
f-> style = 0 |
( lf-> lfItalic ? fsItalic : 0) |
( lf-> lfUnderline ? fsUnderlined : 0) |
Expand All @@ -680,8 +680,8 @@ font_font2logfont( Font * f, LOGFONT * lf)
{
lf-> lfHeight = f-> height;
lf-> lfWidth = f-> width;
lf-> lfEscapement = f-> direction;
lf-> lfOrientation = f-> direction;
lf-> lfEscapement = f-> direction / 10;
lf-> lfOrientation = f-> direction / 10;
lf-> lfWeight = ( f-> style & fsBold) ? 800 : 400;
lf-> lfItalic = ( f-> style & fsItalic) ? 1 : 0;
lf-> lfUnderline = ( f-> style & fsUnderlined) ? 1 : 0;
Expand Down

0 comments on commit 0ac7be9

Please sign in to comment.