Sha256: c7ebfe278714b63741d58e5c1016f73393568a53a0cdfdb8fb5506be30a8d28c

Contents?: true

Size: 1.57 KB

Versions: 20

Compression:

Stored size: 1.57 KB

Contents

# -*- encoding: utf-8 -*-

require 'test_helper'
require 'hexapdf/document'
require 'hexapdf/type/font_descriptor'

describe HexaPDF::Type::FontDescriptor do
  before do
    @doc = HexaPDF::Document.new
    @font_desc = @doc.add({Type: :FontDescriptor, FontName: :Test, Flags: 0b1001001,
                           ItalicAngle: 10})
  end

  describe "flags" do
    it "returns all flags" do
      assert_equal([:fixed_pitch, :script, :italic], @font_desc.flags)
    end
  end

  describe "flagged?" do
    it "returns true if the given flag is set" do
      assert(@font_desc.flagged?(:fixed_pitch))
      refute(@font_desc.flagged?(:serif))
    end

    it "raises an error if an unknown flag name is provided" do
      assert_raises(ArgumentError) { @font_desc.flagged?(:unknown) }
    end
  end

  describe "flag" do
    it "sets the given flag bits" do
      @font_desc.flag(:serif)
      assert_equal([:fixed_pitch, :serif, :script, :italic], @font_desc.flags)
      @font_desc.flag(:symbolic, clear_existing: true)
      assert_equal([:symbolic], @font_desc.flags)
    end
  end

  describe "validation" do
    it "fails if more than one of /FontFile{,2,3} are set" do
      assert(@font_desc.validate {|*args| p args })
      @font_desc[:FontFile] = @font_desc[:FontFile2] = @doc.add({}, stream: 'test')
      refute(@font_desc.validate)
    end

    it "updates the /Descent value if it is not a negative number" do
      @font_desc[:Descent] = 5
      refute(@font_desc.validate(auto_correct: false))
      assert(@font_desc.validate)
      assert_equal(-5, @font_desc[:Descent])
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hexapdf-0.14.4 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.14.3 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.14.2 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.14.1 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.14.0 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.13.0 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.12.3 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.12.2 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.12.1 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.12.0 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.9 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.8 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.7 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.6 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.5 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.4 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.3 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.2 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.1 test/hexapdf/type/test_font_descriptor.rb
hexapdf-0.11.0 test/hexapdf/type/test_font_descriptor.rb