summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Muizelaar <jeff@freiheit.infidigm.net>2007-05-12 23:31:32 -0400
committerJeff Muizelaar <jeff@freiheit.infidigm.net>2007-05-12 23:31:32 -0400
commit79535867d1195e32d0dc0149b5a55357b07ee906 (patch)
treedb03bae54bc7c7e8c29b20e24bf6fcf253ab7066
parenta1cfbd02b4819212638f10a46bdd34cd057e5b0f (diff)
Add a test for the problem in bug 8140
The fonts.pdf has text written with two fonts with the same BaseName but different FontDescriptors that should give different font substitution results.
-rw-r--r--Makefile2
-rwxr-xr-xtest-gen/fonts.pl86
-rw-r--r--tests/fonts.pdf122
-rw-r--r--tests/fonts.pdf-0-cairo-ref.pngbin0 -> 15097 bytes
-rw-r--r--tests/fonts.pdf-0-text-out.txt3
5 files changed, 212 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index ead98f3..60f49de 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CFLAGS = $(shell pkg-config --cflags poppler-glib pango gdk-2.0) -g -Wall -O2
LDLIBS = $(shell pkg-config --libs poppler-glib) -lssl -lpng
PDFNAMES = mask.pdf text.pdf image.pdf type3.pdf cropbox.pdf \
inline-image.pdf degenerate-path.pdf mask-seams.pdf \
- zero-width.pdf encoding.pdf jpeg.pdf
+ zero-width.pdf encoding.pdf jpeg.pdf fonts.pdf
PDFS = $(addprefix tests/, $(PDFNAMES))
diff --git a/test-gen/fonts.pl b/test-gen/fonts.pl
new file mode 100755
index 0000000..0a2b001
--- /dev/null
+++ b/test-gen/fonts.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+
+use Text::PDF::File;
+use Text::PDF::Page; # pulls in Pages
+use Text::PDF::Utils; # not strictly needed
+use Text::PDF::SFont;
+use Text::PDF::Dict;
+do "image.inc";
+$pdf = Text::PDF::File->new; # Make up a new document
+$root = Text::PDF::Pages->new($pdf); # Make a page tree in the document
+$root->bbox(0, 0, 595, 840); # hardwired page size A4 (for this app.) for all pages
+$page = Text::PDF::Page->new($pdf, $root); # Make a new page in the tree
+$font = Text::PDF::SFont->new($pdf, 'Helvetica', 'F0'); # Make a new font in the document
+
+$widths_string = "176 270 369 626 547 692 576 185 313 313 280 533 167 294 184 395 536 380 501 530 499 536 541 391 534 541 202 202 533 533 533 524 774 507 552 553 552 415 397 551 555 288 331 536 380 716 541 546 501 546 538 517 460 546 523 814 482 473 396 282 395 282 483 552 333 503 519 494 519 511 289 518 523 273 279 478 273 770 522 511 519 518 357 470 304 522 437 669 433 448 351 369 270 369 524 750 530 750 167 443 344 553 542 543 333 1024 517 197 688 750 396 750 750 167 167 344 344 347 500 1000 333 782 470 197 765 750 351 473 176 270 517 535 548 473 270 483 333 783 324 371 533 294 783 552 347 533 317 326 333 471 576 333 333 244 329 371 623 645 691 524 507 507 507 507 507 507 713 553 415 415 415 415 288 288 288 288 558 541 546 546 546 546 546 533 546 546 546 546 546 473 501 550 503 503 503 503 503 503 753 494 511 511 511 511 273 273 273 273 511 522 511 511 511 511 511 533 511 522 522 522 522 448 519 448";
+@width_nums = split(/ /, $widths_string);
+my @widths = ();
+foreach (@width_nums) {
+ push @widths, PDFNum($_);
+}
+
+$fontdesc = PDFDict();
+$pdf->new_obj($fontdesc);
+$fontdesc->{'Type'} = PDFName("FontDescriptor");
+$fontdesc->{'FontBBox'} = PDFArray(PDFNum(-129),PDFNum(-330),PDFNum(1261),PDFNum(1167));
+$fontdesc->{'FontName'} = PDFName("NoFont");
+$fontdesc->{'Flags'} = PDFNum(40);
+$fontdesc->{'Ascent'} = PDFNum(1008);
+$fontdesc->{'Descent'} = PDFNum(-210);
+$fontdesc->{'FontWeight'} = PDFNum(900);
+$fontdesc->{'CapHeight'} = PDFNum(0);
+$fontdesc->{'StemV'} = PDFNum(0);
+$fontdesc->{'ItalicAngle'} = PDFNum(0);
+
+$fontdesc2 = PDFDict();
+$pdf->new_obj($fontdesc2);
+$fontdesc2->{'Type'} = PDFName("FontDescriptor");
+$fontdesc2->{'FontBBox'} = PDFArray(PDFNum(-129),PDFNum(-330),PDFNum(1261),PDFNum(1167));
+$fontdesc2->{'FontName'} = PDFName("NoFont");
+$fontdesc2->{'Flags'} = PDFNum(42);
+$fontdesc2->{'Ascent'} = PDFNum(1008);
+$fontdesc2->{'Descent'} = PDFNum(-210);
+$fontdesc2->{'CapHeight'} = PDFNum(0);
+$fontdesc->{'FontWeight'} = PDFNum(900);
+$fontdesc2->{'StemV'} = PDFNum(0);
+$fontdesc2->{'ItalicAngle'} = PDFNum(0);
+
+$ttfont = Text::PDF::Dict->new($pdf);
+$ttfont->{'Type'} = PDFName("Font");
+$ttfont->{'Subtype'} = PDFName("TrueType");
+$ttfont->{'Name'} = PDFName("F1");
+$ttfont->{'BaseFont'} = PDFName("NoFont");
+$ttfont->{'FirstChar'} = PDFNum(32);
+$ttfont->{'LastChar'} = PDFNum(255);
+$ttfont->{'FontDescriptor'} = $fontdesc;
+$ttfont->{'Widths'} = PDFArray(@widths);
+$ttfont2 = Text::PDF::Dict->new($pdf);
+$ttfont2->{'Type'} = PDFName("Font");
+$ttfont2->{'Subtype'} = PDFName("TrueType");
+$ttfont2->{'Name'} = PDFName("F2");
+$ttfont2->{'FirstChar'} = PDFNum(32);
+$ttfont2->{'LastChar'} = PDFNum(255);
+$ttfont2->{'BaseFont'} = PDFName("NoFont");
+$ttfont2->{'FontDescriptor'} = $fontdesc2;
+$ttfont2->{'Widths'} = PDFArray(@widths);
+$pdf->new_obj($ttfont);
+$pdf->new_obj($ttfont2);
+$root->add_font($font); # Tell all pages about the font
+$root->add_font($ttfont); # Tell all pages about the font
+$root->add_font($ttfont2); # Tell all pages about the font
+
+$x = 100;
+$y = 500;
+$sx = $w;
+$sy = $h;
+
+# draw some black text
+$page->add("0 0 1 rg\n");
+$page->add("BT 1 0 0 1 100 600 Tm /F0 48 Tf 0 Tr (Hello World!) Tj ET\n");
+$page->add("BT 1 0 0 1 100 500 Tm /F1 48 Tf 0 Tr (Hello World!) Tj ET\n");
+$page->add("BT 1 0 0 1 100 400 Tm /F2 48 Tf 0 Tr (Hello World!) Tj ET\n");
+
+$page->add("q\nQ");
+$pdf->out_file($ARGV[0]); # output the document to a file
+
+# all done!
diff --git a/tests/fonts.pdf b/tests/fonts.pdf
new file mode 100644
index 0000000..3e3a497
--- /dev/null
+++ b/tests/fonts.pdf
@@ -0,0 +1,122 @@
+%PDF-1.2
+%Çì¢
+1 0 obj
+<<
+/Type /Catalog
+/Pages 2 0 R
+>>
+endobj
+2 0 obj
+<<
+/Type /Pages
+/Kids [ 3 0 R ]
+/MediaBox [ 0 0 595 840 ]
+/Resources <<
+/Font <<
+/F0 4 0 R
+/F2 8 0 R
+/F1 7 0 R
+>>
+>>
+/Count 1
+>>
+endobj
+3 0 obj
+<<
+/Type /Page
+/Contents [ 9 0 R ]
+/Parent 2 0 R
+>>
+endobj
+4 0 obj
+<<
+/Type /Font
+/Subtype /Type1
+/BaseFont /Helvetica
+/Name /F0
+>>
+endobj
+5 0 obj
+<<
+/Type /FontDescriptor
+/Ascent 1008
+/Flags 40
+/Descent -210
+/ItalicAngle 0
+/StemV 0
+/CapHeight 0
+/FontWeight 900
+/FontBBox [ -129 -330 1261 1167 ]
+/FontName /NoFont
+>>
+endobj
+6 0 obj
+<<
+/Type /FontDescriptor
+/Ascent 1008
+/Flags 42
+/Descent -210
+/ItalicAngle 0
+/StemV 0
+/CapHeight 0
+/FontBBox [ -129 -330 1261 1167 ]
+/FontName /NoFont
+>>
+endobj
+7 0 obj
+<<
+/Type /Font
+/Subtype /TrueType
+/FirstChar 32
+/BaseFont /NoFont
+/LastChar 255
+/Widths [ 176 270 369 626 547 692 576 185 313 313 280 533 167 294 184 395 536 380 501 530 499 536 541 391 534 541 202 202 533 533 533 524 774 507 552 553 552 415 397 551 555 288 331 536 380 716 541 546 501 546 538 517 460 546 523 814 482 473 396 282 395 282 483 552 333 503 519 494 519 511 289 518 523 273 279 478 273 770 522 511 519 518 357 470 304 522 437 669 433 448 351 369 270 369 524 750 530 750 167 443 344 553 542 543 333 1024 517 197 688 750 396 750 750 167 167 344 344 347 500 1000 333 782 470 197 765 750 351 473 176 270 517 535 548 473 270 483 333 783 324 371 533 294 783 552 347 533 317 326 333 471 576 333 333 244 329 371 623 645 691 524 507 507 507 507 507 507 713 553 415 415 415 415 288 288 288 288 558 541 546 546 546 546 546 533 546 546 546 546 546 473 501 550 503 503 503 503 503 503 753 494 511 511 511 511 273 273 273 273 511 522 511 511 511 511 511 533 511 522 522 522 522 448 519 448 ]
+/FontDescriptor 5 0 R
+/Name /F1
+>>
+endobj
+8 0 obj
+<<
+/Type /Font
+/Subtype /TrueType
+/FirstChar 32
+/BaseFont /NoFont
+/LastChar 255
+/Widths [ 176 270 369 626 547 692 576 185 313 313 280 533 167 294 184 395 536 380 501 530 499 536 541 391 534 541 202 202 533 533 533 524 774 507 552 553 552 415 397 551 555 288 331 536 380 716 541 546 501 546 538 517 460 546 523 814 482 473 396 282 395 282 483 552 333 503 519 494 519 511 289 518 523 273 279 478 273 770 522 511 519 518 357 470 304 522 437 669 433 448 351 369 270 369 524 750 530 750 167 443 344 553 542 543 333 1024 517 197 688 750 396 750 750 167 167 344 344 347 500 1000 333 782 470 197 765 750 351 473 176 270 517 535 548 473 270 483 333 783 324 371 533 294 783 552 347 533 317 326 333 471 576 333 333 244 329 371 623 645 691 524 507 507 507 507 507 507 713 553 415 415 415 415 288 288 288 288 558 541 546 546 546 546 546 533 546 546 546 546 546 473 501 550 503 503 503 503 503 503 753 494 511 511 511 511 273 273 273 273 511 522 511 511 511 511 511 533 511 522 522 522 522 448 519 448 ]
+/FontDescriptor 6 0 R
+/Name /F2
+>>
+endobj
+9 0 obj
+<<
+/Length 187
+>>
+stream
+0 0 1 rg
+BT 1 0 0 1 100 600 Tm /F0 48 Tf 0 Tr (Hello World!) Tj ET
+BT 1 0 0 1 100 500 Tm /F1 48 Tf 0 Tr (Hello World!) Tj ET
+BT 1 0 0 1 100 400 Tm /F2 48 Tf 0 Tr (Hello World!) Tj ET
+q
+Q
+endstream
+endobj
+xref
+0 10
+0000000000 65535 f
+0000000015 00000 n
+0000000064 00000 n
+0000000208 00000 n
+0000000275 00000 n
+0000000355 00000 n
+0000000540 00000 n
+0000000709 00000 n
+0000001749 00000 n
+0000002789 00000 n
+trailer
+<<
+/Root 1 0 R
+/Size 10
+>>
+startxref
+3026
+%%EOF
diff --git a/tests/fonts.pdf-0-cairo-ref.png b/tests/fonts.pdf-0-cairo-ref.png
new file mode 100644
index 0000000..2151069
--- /dev/null
+++ b/tests/fonts.pdf-0-cairo-ref.png
Binary files differ
diff --git a/tests/fonts.pdf-0-text-out.txt b/tests/fonts.pdf-0-text-out.txt
new file mode 100644
index 0000000..8baa6e3
--- /dev/null
+++ b/tests/fonts.pdf-0-text-out.txt
@@ -0,0 +1,3 @@
+Hello World!
+Hello World!
+Hello World!