From 41403fe33faa66b6d6c06febea7c76e5ad59c18f Mon Sep 17 00:00:00 2001 From: Alexander Mankuta Date: Fri, 6 Dec 2019 12:49:40 +0200 Subject: [PATCH] Use module namespace for fonts --- lib/prawn/font.rb | 23 +++++++++++++++-------- lib/prawn/{font => fonts}/afm.rb | 6 +++--- lib/prawn/{font => fonts}/dfont.rb | 2 +- lib/prawn/{font => fonts}/ttc.rb | 2 +- lib/prawn/{font => fonts}/ttf.rb | 2 +- lib/prawn/text.rb | 2 +- manual/example_helper.rb | 2 +- spec/prawn/font_spec.rb | 4 ++-- spec/spec_helper.rb | 2 +- 9 files changed, 26 insertions(+), 19 deletions(-) rename lib/prawn/{font => fonts}/afm.rb (98%) rename lib/prawn/{font => fonts}/dfont.rb (98%) rename lib/prawn/{font => fonts}/ttc.rb (98%) rename lib/prawn/{font => fonts}/ttf.rb (99%) diff --git a/lib/prawn/font.rb b/lib/prawn/font.rb index 51a43723a..b9ca085c3 100644 --- a/lib/prawn/font.rb +++ b/lib/prawn/font.rb @@ -6,10 +6,6 @@ # # This is free software. Please see the LICENSE and COPYING files for details. # -require_relative 'font/afm' -require_relative 'font/ttf' -require_relative 'font/dfont' -require_relative 'font/ttc' require_relative 'font_metric_cache' module Prawn @@ -37,7 +33,7 @@ class Document # # The :name parameter must be a string. It can be one of the 14 built-in # fonts supported by PDF, or the location of a TTF file. The - # Font::AFM::BUILT_INS array specifies the valid built in font values. + # Fonts::AFM::BUILT_INS array specifies the valid built in font values. # # If a ttf font is specified, the glyphs necessary to render your document # will be embedded in the rendered PDF. This should be your preferred option @@ -283,6 +279,17 @@ def width_of_string(string, options = {}) # Provides font information and helper functions. # class Font + require_relative 'fonts/afm' + require_relative 'fonts/ttf' + require_relative 'fonts/dfont' + require_relative 'fonts/ttc' + + # @deprecated + AFM = Fonts::AFM + TTF = Fonts::TTF + DFont = Fonts::DFont + TTC = Fonts::TTC + # The current font name attr_reader :name @@ -293,9 +300,9 @@ class Font attr_reader :options # Shortcut interface for constructing a font object. Filenames of the form - # *.ttf will call Font::TTF.new, *.dfont Font::DFont.new, *.ttc goes to - # Font::TTC.new, and anything else will be passed through to - # Font::AFM.new() + # *.ttf will call Fonts::TTF.new, *.dfont Fonts::DFont.new, *.ttc goes to + # Fonts::TTC.new, and anything else will be passed through to + # Fonts::AFM.new() def self.load(document, src, options = {}) case font_format(src, options) when 'ttf' then TTF.new(document, src, options) diff --git a/lib/prawn/font/afm.rb b/lib/prawn/fonts/afm.rb similarity index 98% rename from lib/prawn/font/afm.rb rename to lib/prawn/fonts/afm.rb index 3c33302f4..aedbbca67 100644 --- a/lib/prawn/font/afm.rb +++ b/lib/prawn/fonts/afm.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# prawn/font/afm.rb : Implements AFM font support for Prawn +# Implements AFM font support for Prawn # # Copyright May 2008, Gregory Brown / James Healy. All Rights Reserved. # @@ -9,7 +9,7 @@ require_relative '../encoding' module Prawn - class Font + module Fonts # @private class AFM < Font @@ -113,7 +113,7 @@ def normalize_encoding(text) raise Prawn::Errors::IncompatibleStringEncoding, "Your document includes text that's not compatible with the " \ "Windows-1252 character set.\n" \ - "If you need full UTF-8 support, use TTF fonts instead of PDF's " \ + "If you need full UTF-8 support, use external fonts instead of PDF's " \ "built-in fonts.\n" end diff --git a/lib/prawn/font/dfont.rb b/lib/prawn/fonts/dfont.rb similarity index 98% rename from lib/prawn/font/dfont.rb rename to lib/prawn/fonts/dfont.rb index 881789859..9b805ec28 100644 --- a/lib/prawn/font/dfont.rb +++ b/lib/prawn/fonts/dfont.rb @@ -3,7 +3,7 @@ require_relative 'ttf' module Prawn - class Font + module Fonts # @private class DFont < TTF # Returns a list of the names of all named fonts in the given dfont file. diff --git a/lib/prawn/font/ttc.rb b/lib/prawn/fonts/ttc.rb similarity index 98% rename from lib/prawn/font/ttc.rb rename to lib/prawn/fonts/ttc.rb index e098b890f..040c0cb45 100644 --- a/lib/prawn/font/ttc.rb +++ b/lib/prawn/fonts/ttc.rb @@ -3,7 +3,7 @@ require_relative 'ttf' module Prawn - class Font + module Fonts # @private class TTC < TTF # Returns a list of the names of all named fonts in the given ttc file. diff --git a/lib/prawn/font/ttf.rb b/lib/prawn/fonts/ttf.rb similarity index 99% rename from lib/prawn/font/ttf.rb rename to lib/prawn/fonts/ttf.rb index b5f7bd2c7..9ebc792c8 100644 --- a/lib/prawn/font/ttf.rb +++ b/lib/prawn/fonts/ttf.rb @@ -11,7 +11,7 @@ require 'ttfunk/subset_collection' module Prawn - class Font + module Fonts # @private class TTF < Font attr_reader :ttf, :subsets diff --git a/lib/prawn/text.rb b/lib/prawn/text.rb index 06a46449c..62ce1f8ed 100644 --- a/lib/prawn/text.rb +++ b/lib/prawn/text.rb @@ -296,7 +296,7 @@ def draw_text!(text, options) "internationalized text.\nIf you need full UTF-8 support, " \ "consider using a TTF font instead.\n\nTo disable this " \ "warning, add the following line to your code:\n" \ - "Prawn::Font::AFM.hide_m17n_warning = true\n" + "Prawn::Fonts::AFM.hide_m17n_warning = true\n" font.class.hide_m17n_warning = true end diff --git a/manual/example_helper.rb b/manual/example_helper.rb index 5d46c9f55..110aef80a 100644 --- a/manual/example_helper.rb +++ b/manual/example_helper.rb @@ -5,4 +5,4 @@ require 'prawn/manual_builder' Prawn::ManualBuilder.manual_dir = File.dirname(__FILE__) -Prawn::Font::AFM.hide_m17n_warning = true +Prawn::Fonts::AFM.hide_m17n_warning = true diff --git a/spec/prawn/font_spec.rb b/spec/prawn/font_spec.rb index d85e69d45..f654e305f 100644 --- a/spec/prawn/font_spec.rb +++ b/spec/prawn/font_spec.rb @@ -461,14 +461,14 @@ def page_should_not_include_font(font) let(:file) { "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont" } it 'lists all named fonts' do - list = Prawn::Font::DFont.named_fonts(file) + list = Prawn::Fonts::DFont.named_fonts(file) expect(list).to match_array(%w[ PanicSans PanicSans-Bold PanicSans-BoldItalic PanicSans-Italic ]) end it 'counts the number of fonts in the file' do - expect(Prawn::Font::DFont.font_count(file)).to eq(4) + expect(Prawn::Fonts::DFont.font_count(file)).to eq(4) end it 'defaults selected font to the first one if not specified' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0befae63c..4fe27ff52 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,7 @@ require_relative '../lib/prawn' Prawn.debug = true -Prawn::Font::AFM.hide_m17n_warning = true +Prawn::Fonts::AFM.hide_m17n_warning = true require 'rspec' require 'pdf/reader'