From: Matthias Kramm Date: Wed, 19 Aug 2009 14:44:37 +0000 (+0200) Subject: added text selection test to testsuite X-Git-Tag: version-0-9-1~299 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=9188f342f67f399dbb7857dd1970ab44a8c24138;p=swftools.git added text selection test to testsuite --- diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cf9c971..bbfe1a5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -53,7 +53,8 @@ class Area @rgb.minmax != [@rgb[0],@rgb[0]] or raise AreaError.new(self,"is plain colored") end def should_contain_text(text) - @file.get_text(@x1,@y1,@x2,@y2) == text or raise AreaError.new(self, "doesn't contain text #{text}") + text2 = @file.get_text(@x1,@y1,@x2,@y2) + text2 == text or raise AreaError.new(self, "doesn't contain text \"#{text}\" (found: \"#{text2}\")") end def to_s "(#{@x1},#{@y1},#{@x2},#{@y2})" diff --git a/spec/textselectspaces.pdf b/spec/textselectspaces.pdf new file mode 100644 index 0000000..0a35174 --- /dev/null +++ b/spec/textselectspaces.pdf @@ -0,0 +1,147 @@ +%PDF-1.6 +%äãÏÒ +1 0 obj +[/PDF/ImageB/ImageC/ImageI/Text] +endobj +4 0 obj +<> +stream +xœm»Â0 EwEFâÄNÛµLŒþ +A‚Ï')µªK9º9¾r#°Ú8ƒ•‘òÜ¥gtFö°ãa)g`´É|Ùýyj/™FŸ¨ÿÑÝ£ÝZ²]ÿάÀ*eÉa¢%U˪–U-kÚà5-UëæÚµ€·œXºÃ0Û+4M9݃–•=éï|գ쿾–çõ£Z¿Të“ZÿZépi +endstream +endobj +5 0 obj +166 +endobj +7 0 obj +<> +>> +endobj +8 0 obj +<> +endobj +6 0 obj +<> +endobj +10 0 obj +<> +endobj +9 0 obj +<> +endobj +3 0 obj +<> +endobj +2 0 obj +<> +endobj +11 0 obj +<> +endobj +xref +0 12 +0000000000 65535 f +0000000015 00000 n +0000002348 00000 n +0000002247 00000 n +0000000063 00000 n +0000000301 00000 n +0000000514 00000 n +0000000320 00000 n +0000000375 00000 n +0000002066 00000 n +0000001681 00000 n +0000002402 00000 n +trailer +<<8F26BB647D55ECD56991EB3EFE624E02>] +>> +startxref +2450 +%%EOF diff --git a/spec/textselectspaces.py b/spec/textselectspaces.py new file mode 100644 index 0000000..737744f --- /dev/null +++ b/spec/textselectspaces.py @@ -0,0 +1,63 @@ +from sys import * +from pdflib_py import * +p = PDF_new() +PDF_open_file(p, "textselectspaces.pdf") + +PDF_set_parameter(p, "usercoordinates", "true") + +PDF_set_info(p, "Creator", "smalltext.py") +PDF_begin_page(p, 612, 200) +font = PDF_load_font(p, "Helvetica", "host", "") + +PDF_setfont(p, font, 18.0) + +x = 40 +y = 100 +def write_word(s, d): + global x,y + w = PDF_stringwidth(p, s, font, 18.0) + PDF_show(p, s) + x+=w+d + PDF_set_text_pos(p, x, y) + +x,y = 40,160 +PDF_set_text_pos(p, x, y) +write_word("The", 20) +write_word("quick", 20) +write_word("brown", 20) +write_word("fox", 20) + +x,y = 40,130 +PDF_set_text_pos(p, x, y) +write_word("The", 10) +write_word("quick", 10) +write_word("brown", 10) +write_word("fox", 10) + +x,y = 40,100 +PDF_set_text_pos(p, x, y) +write_word("The", 1) +write_word("quick", 1) +write_word("brown", 1) +write_word("fox", 1) + +PDF_setmatrix(p, 2.5, 0, 0, 1.0, 0, 0) +x,y = 16,70 +PDF_set_text_pos(p, x, y) +write_word("The", 0.5) +write_word("quick", 0.5) +write_word("brown", 0.5) +write_word("fox", 0.5) + +PDF_setmatrix(p, 2.5, 0, 0, 1.0, 0, 0) +x,y = 16,40 +PDF_set_text_pos(p, x, y) +write_word("The", 5) +write_word("quick", 5) +write_word("brown", 5) +write_word("fox", 5) + + +PDF_end_page(p) +PDF_close(p) +PDF_delete(p); diff --git a/spec/textselectspaces.spec.rb b/spec/textselectspaces.spec.rb new file mode 100644 index 0000000..8e126a5 --- /dev/null +++ b/spec/textselectspaces.spec.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe "pdf conversion" do + convert_file "textselectspaces.pdf" do + area_at(32,22,257,46).should_contain_text 'The quick brown fox' + area_at(32,53,226,77).should_contain_text 'The quick brown fox' + area_at(31,84,198,108).should_contain_text 'Thequickbrownfox' + area_at(33,111,423,137).should_contain_text 'Thequickbrownfox' + area_at(35,141,455,167).should_contain_text 'The quick brown fox' + end +end