Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use the standard font tests for Freetype 1.x (TT) too

and fix the code to pass them
  • Loading branch information...
commit 7e3298ec06ae0d1794cc6c006439ecc26f0ce7ed 1 parent d6f02a5
Tony Cook authored February 23, 2013
23  Imager.xs
@@ -2289,7 +2289,7 @@ i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8,align=1)
2289 2289
 
2290 2290
 
2291 2291
 void
2292  
-i_tt_bbox(handle,point,str_sv,len_ignored, utf8)
  2292
+i_tt_bbox(handle,point,str_sv,utf8)
2293 2293
   Imager::Font::TT     handle
2294 2294
 	     double     point
2295 2295
 	       SV*    str_sv
@@ -2301,11 +2301,11 @@ i_tt_bbox(handle,point,str_sv,len_ignored, utf8)
2301 2301
                STRLEN len;
2302 2302
                int i;
2303 2303
 	     PPCODE:
  2304
+               str = SvPV(str_sv, len);
2304 2305
 #ifdef SvUTF8
2305 2306
                if (SvUTF8(ST(2)))
2306 2307
                  utf8 = 1;
2307 2308
 #endif
2308  
-               str = SvPV(str_sv, len);
2309 2309
   	       if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) {
2310 2310
                  EXTEND(SP, rc);
2311 2311
                  for (i = 0; i < rc; ++i) {
@@ -2325,11 +2325,12 @@ i_tt_has_chars(handle, text_sv, utf8)
2325 2325
         size_t count;
2326 2326
         size_t i;
2327 2327
       PPCODE:
  2328
+        i_clear_error();
  2329
+        text = SvPV(text_sv, len);
2328 2330
 #ifdef SvUTF8
2329 2331
         if (SvUTF8(text_sv))
2330 2332
           utf8 = 1;
2331 2333
 #endif
2332  
-        text = SvPV(text_sv, len);
2333 2334
         work = mymalloc(len);
2334 2335
         count = i_tt_has_chars(handle, text, len, utf8, work);
2335 2336
         if (GIMME_V == G_ARRAY) {
@@ -2372,12 +2373,14 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
2372 2373
         size_t len;
2373 2374
         size_t outsize;
2374 2375
         char name[255];
  2376
+	SSize_t count = 0;
2375 2377
       PPCODE:
  2378
+        i_clear_error();
  2379
+        text = SvPV(text_sv, work_len);
2376 2380
 #ifdef SvUTF8
2377 2381
         if (SvUTF8(text_sv))
2378 2382
           utf8 = 1;
2379 2383
 #endif
2380  
-        text = SvPV(text_sv, work_len);
2381 2384
         len = work_len;
2382 2385
         while (len) {
2383 2386
           unsigned long ch;
@@ -2385,21 +2388,23 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
2385 2388
             ch = i_utf8_advance(&text, &len);
2386 2389
             if (ch == ~0UL) {
2387 2390
               i_push_error(0, "invalid UTF8 character");
2388  
-              break;
  2391
+              XSRETURN_EMPTY;
2389 2392
             }
2390 2393
           }
2391 2394
           else {
2392 2395
             ch = *text++;
2393 2396
             --len;
2394 2397
           }
2395  
-          EXTEND(SP, 1);
  2398
+          EXTEND(SP, count);
2396 2399
           if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
2397  
-            PUSHs(sv_2mortal(newSVpv(name, 0)));
  2400
+	    ST(count) = sv_2mortal(newSVpv(name, 0));
2398 2401
           }
2399 2402
           else {
2400  
-            PUSHs(&PL_sv_undef);
2401  
-          } 
  2403
+	    ST(count) = &PL_sv_undef;
  2404
+          }
  2405
+          ++count;
2402 2406
         }
  2407
+	XSRETURN(count);
2403 2408
 
2404 2409
 #endif 
2405 2410
 
1  MANIFEST
@@ -343,6 +343,7 @@ t/t22flood.t			Flood fill tests
343 343
 t/t31font.t			General font interface tests
344 344
 t/t35ttfont.t
345 345
 t/t36oofont.t
  346
+t/t37std.t			Standard font tests for TT
346 347
 t/t40scale.t
347 348
 t/t50basicoo.t
348 349
 t/t55trans.t
46  lib/Imager/Font/Truetype.pm
@@ -66,9 +66,14 @@ sub _draw {
66 66
 sub _bounding_box {
67 67
   my $self = shift;
68 68
   my %input = @_;
69  
-  return Imager::i_tt_bbox($self->{id}, $input{size},
70  
-			   $input{string}, length($input{string}),
71  
-                           $input{utf8});
  69
+  my @result =
  70
+    Imager::i_tt_bbox($self->{id}, $input{size}, $input{string}, $input{utf8});
  71
+  unless (@result) {
  72
+    Imager->_set_error(Imager->_error_as_msg);
  73
+    return;
  74
+  }
  75
+
  76
+  return @result;
72 77
 }
73 78
 
74 79
 sub utf8 { 1 }
@@ -77,12 +82,29 @@ sub utf8 { 1 }
77 82
 sub has_chars {
78 83
   my ($self, %hsh) = @_;
79 84
 
80  
-  unless (defined $hsh{string} && length $hsh{string}) {
  85
+  unless (defined $hsh{string}) {
81 86
     $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
82 87
     return;
83 88
   }
84  
-  return Imager::i_tt_has_chars($self->{id}, $hsh{string}, 
85  
-				_first($hsh{'utf8'}, $self->{utf8}, 0));
  89
+  if (wantarray) {
  90
+    my @result = Imager::i_tt_has_chars($self->{id}, $hsh{string}, 
  91
+					_first($hsh{'utf8'}, $self->{utf8}, 0));
  92
+    unless (@result) {
  93
+      Imager->_set_error(Imager->_error_as_msg);
  94
+      return;
  95
+    }
  96
+    return @result;
  97
+  }
  98
+  else {
  99
+    my $result = Imager::i_tt_has_chars($self->{id}, $hsh{string}, 
  100
+					_first($hsh{'utf8'}, $self->{utf8}, 0));
  101
+    unless (defined $result) {
  102
+      Imager->_set_error(Imager->_error_as_msg);
  103
+      return;
  104
+    }
  105
+
  106
+    return $result;
  107
+  }
86 108
 }
87 109
 
88 110
 sub face_name {
@@ -91,6 +113,10 @@ sub face_name {
91 113
   Imager::i_tt_face_name($self->{id});
92 114
 }
93 115
 
  116
+sub can_glyph_names {
  117
+  1;
  118
+}
  119
+
94 120
 sub glyph_names {
95 121
   my ($self, %input) = @_;
96 122
 
@@ -99,7 +125,13 @@ sub glyph_names {
99 125
     or return Imager->_set_error("no string parameter passed to glyph_names");
100 126
   my $utf8 = _first($input{utf8} || 0);
101 127
 
102  
-  Imager::i_tt_glyph_name($self->{id}, $string, $utf8);
  128
+  my @names = Imager::i_tt_glyph_name($self->{id}, $string, $utf8);
  129
+  unless (@names) {
  130
+    Imager->_set_error(Imager->_error_as_msg);
  131
+    return;
  132
+  }
  133
+
  134
+  return @names;
103 135
 }
104 136
 
105 137
 1;
8  t/t35ttfont.t
@@ -35,7 +35,7 @@ SKIP:
35 35
   my $ttraw = Imager::i_tt_new($fontname);
36 36
   ok($ttraw, "create font");
37 37
 
38  
-  my @bbox = i_tt_bbox($ttraw,50.0,'XMCLH',6,0);
  38
+  my @bbox = i_tt_bbox($ttraw,50.0,'XMCLH',0);
39 39
   is(@bbox, 8, "bounding box");
40 40
   print "#bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
41 41
 
@@ -77,9 +77,9 @@ SKIP:
77 77
   my $text = pack("C*", 0x41, 0xE2, 0x80, 0x90, 0x41);
78 78
   my $alttext = "A-A";
79 79
   
80  
-  my @utf8box = i_tt_bbox($ttraw, 50.0, $text, length($text), 1);
  80
+  my @utf8box = i_tt_bbox($ttraw, 50.0, $text, 1);
81 81
   is(@utf8box, 8, "utf8 bbox element count");
82  
-  my @base = i_tt_bbox($ttraw, 50.0, $alttext, length($alttext), 0);
  82
+  my @base = i_tt_bbox($ttraw, 50.0, $alttext, 0);
83 83
   is(@base, 8, "alt bbox element count");
84 84
   my $maxdiff = $fontname eq $deffont ? 0 : $base[2] / 3;
85 85
   print "# (@utf8box vs @base)\n";
@@ -106,7 +106,7 @@ SKIP:
106 106
        "draw UTF8");
107 107
     ok(i_tt_cp($ttraw, $backgr, 350, 80, 0, 14, $text, 0, 1, 0),
108 108
        "cp UTF8");
109  
-    @utf8box = i_tt_bbox($ttraw, 50.0, $text, length($text), 0);
  109
+    @utf8box = i_tt_bbox($ttraw, 50.0, $text, 0);
110 110
     is(@utf8box, 8, "native utf8 bbox element count");
111 111
     ok(abs($utf8box[2] - $base[2]) <= $maxdiff, 
112 112
        "compare box sizes native $utf8box[2] vs $base[2] (maxerror $maxdiff)");
29  t/t37std.t
... ...
@@ -0,0 +1,29 @@
  1
+#!perl -w
  2
+use strict;
  3
+use Imager::Test qw(std_font_tests std_font_test_count);
  4
+use Imager::Font;
  5
+use Test::More;
  6
+
  7
+$Imager::formats{tt}
  8
+	or plan skip_all => "No tt available";
  9
+
  10
+plan tests => std_font_test_count();
  11
+
  12
+my $font = Imager::Font->new(file => "fontfiles/dodge.ttf",
  13
+			     type => "tt");
  14
+my $name_font =
  15
+  Imager::Font->new(file => "fontfiles/ImUgly.ttf",
  16
+		    type => "tt");
  17
+
  18
+SKIP:
  19
+{
  20
+  $font
  21
+    or skip "Cannot load font", std_font_test_count();
  22
+  std_font_tests
  23
+    ({
  24
+      font => $font,
  25
+      has_chars => [ 1, 1, 1 ],
  26
+      glyph_name_font => $name_font,
  27
+      glyph_names => [ qw(A uni2010 A) ],
  28
+     });
  29
+}

0 notes on commit 7e3298e

Please sign in to comment.
Something went wrong with that request. Please try again.