test/hexapdf/content/test_canvas.rb in hexapdf-0.5.0 vs test/hexapdf/content/test_canvas.rb in hexapdf-0.6.0

- old
+ new

@@ -85,10 +85,21 @@ it "is serialized correctly when a block is used" do @canvas.save_graphics_state { } assert_operators(@canvas.contents, [[:save_graphics_state], [:restore_graphics_state]]) end + it "saves needed font state information not stored in the graphics state" do + @canvas.save_graphics_state do + @canvas.font("Times", size: 12) + @canvas.save_graphics_state do + @canvas.font("Helvetica") + end + assert_equal("Times-Roman", @canvas.font.wrapped_font.font_name) + end + assert_nil(@canvas.font) + end + it "fails if invoked while in an unsupported graphics objects" do assert_raises_in_graphics_object(:path, :clipping_path) { @canvas.save_graphics_state } end end @@ -997,22 +1008,22 @@ describe "font" do it "returns the set font" do assert_nil(@canvas.font) @canvas.font("Times", size: 10) - assert_same(@doc.fonts.load("Times"), @canvas.font) + assert_same(@doc.fonts.add("Times"), @canvas.font) @canvas.font(@canvas.font) - assert_same(@doc.fonts.load("Times"), @canvas.font) + assert_same(@doc.fonts.add("Times"), @canvas.font) @canvas.font("Helvetica", size: 10) assert_operators(@canvas.contents, [[:set_font_and_size, [:F1, 10]], [:set_leading, [12.0]], [:set_font_and_size, [:F2, 10]]]) end it "sets the font and optionally the font size" do @canvas.font("Times", size: 12, variant: :italic) - assert_same(@doc.fonts.load("Times", variant: :italic), @canvas.font) + assert_same(@doc.fonts.add("Times", variant: :italic), @canvas.font) assert_equal(12, @canvas.font_size) @canvas.font("Helvetica") assert_equal(12, @canvas.font_size) end end @@ -1064,10 +1075,15 @@ [:set_font_and_size, [:F1, 10]], [:set_leading, [12]], [:show_text_with_positioning, [["Hal"]]], ]) end + + it "fails if no valid font is set" do + error = assert_raises(HexaPDF::Error) { @canvas.show_glyphs([]) } + assert_match(/if a font is set/, error.message) + end end describe "show_glyphs_only" do it "serializes correctly" do @canvas.font("Times", size: 20) @@ -1079,10 +1095,15 @@ [:set_leading, [24]], [:begin_text], [:show_text_with_positioning, [["Ha", -35, "l lo"]]], ]) end + + it "fails if no valid font is set" do + error = assert_raises(HexaPDF::Error) { @canvas.show_glyphs([]) } + assert_match(/if a font is set/, error.message) + end end describe "text" do it "sets the text cursor position if instructed" do @canvas.font("Times", size: 10) @@ -1109,9 +1130,14 @@ [:show_text_with_positioning, [["H"]]], [:move_text_next_line], [:show_text_with_positioning, [["H"]]], [:move_text_next_line], [:show_text_with_positioning, [["H"]]], [:move_text_next_line], [:show_text_with_positioning, [["H"]]], ]) + end + + it "fails if no valid font is set" do + error = assert_raises(HexaPDF::Error) { @canvas.show_glyphs([]) } + assert_match(/if a font is set/, error.message) end end describe "marked_content_point" do it "invokes the operator implementation" do