From 0ac7be941902f77b60e3fc5cf156f18dab8b89c3 Mon Sep 17 00:00:00 2001 From: dk Date: Thu, 25 Oct 2007 11:24:27 +0000 Subject: [PATCH] - Font::direction is now double, in degrees, in contrast as it was before - int, in tenths of a degree. --- Prima/PS/Drawable.pm | 6 +++--- Types.cls | 2 +- examples/fontdlg.pl | 4 ++-- examples/matrix.pl | 16 ++++++++-------- include/unix/guts.h | 5 +++-- os2/gp.c | 4 ++-- pod/Prima/Drawable.pod | 6 ++---- unix/apc_font.c | 27 +++++++++++++++++++++------ unix/apc_graphics.c | 17 ++++++++++------- unix/xft.c | 10 +++++----- win32/gp.c | 4 ++-- win32/stock.c | 6 +++--- 12 files changed, 62 insertions(+), 45 deletions(-) diff --git a/Prima/PS/Drawable.pm b/Prima/PS/Drawable.pm index 428f30ecc..43939d059 100644 --- a/Prima/PS/Drawable.pm +++ b/Prima/PS/Drawable.pm @@ -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; @@ -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]; diff --git a/Types.cls b/Types.cls index 7a9ad17ee..52696def6 100644 --- a/Types.cls +++ b/Types.cls @@ -42,7 +42,7 @@ global %Font { int width ; int style ; int pitch ; - int direction ; + double direction ; long resolution ; string name ; int size ; diff --git a/examples/fontdlg.pl b/examples/fontdlg.pl index 592bfe532..460053f83 100644 --- a/examples/fontdlg.pl +++ b/examples/fontdlg.pl @@ -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 => @@ -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++) { diff --git a/examples/matrix.pl b/examples/matrix.pl index c5860d12c..f64b20b0d 100644 --- a/examples/matrix.pl +++ b/examples/matrix.pl @@ -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 @@ -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; @@ -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, ); } @@ -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 { diff --git a/include/unix/guts.h b/include/unix/guts.h index 21dd02846..dabf1caae 100644 --- a/include/unix/guts.h +++ b/include/unix/guts.h @@ -181,7 +181,7 @@ typedef struct _FontInfo { } FontInfo, *PFontInfo; typedef struct _RotatedFont { - int direction; + double direction; int first1; int first2; int height; @@ -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); diff --git a/os2/gp.c b/os2/gp.c index d471159b9..98d99e7bb 100644 --- a/os2/gp.c +++ b/os2/gp.c @@ -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); @@ -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; diff --git a/pod/Prima/Drawable.pod b/pod/Prima/Drawable.pod index 83c031ab9..ccb67624b 100644 --- a/pod/Prima/Drawable.pod +++ b/pod/Prima/Drawable.pod @@ -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 diff --git a/unix/apc_font.c b/unix/apc_font.c index 2a85f3fe3..a4dc6acab 100644 --- a/unix/apc_font.c +++ b/unix/apc_font.c @@ -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); @@ -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) { @@ -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; diff --git a/unix/apc_graphics.c b/unix/apc_graphics.c index 50b394698..60e88b757 100644 --- a/unix/apc_graphics.c +++ b/unix/apc_graphics.c @@ -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; @@ -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++) { @@ -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) @@ -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; diff --git a/unix/xft.c b/unix/xft.c index 91f0145cd..1ccc228f8 100644 --- a/unix/xft.c +++ b/unix/xft.c @@ -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); } @@ -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; @@ -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; diff --git a/win32/gp.c b/win32/gp.c index 9b27a0d0d..0b1b50154 100644 --- a/win32/gp.c +++ b/win32/gp.c @@ -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; diff --git a/win32/stock.c b/win32/stock.c index 7ecdaa1f6..c8a5b8fac 100644 --- a/win32/stock.c +++ b/win32/stock.c @@ -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) | @@ -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;