Sha256: 28fce91e35abec69684811f364a7a517cf1895b31c4ae0499c6a3216a65bd36b

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8
#
# Prints a list of all of the glyphs that can be rendered by Adobe's built
# in fonts, along with their character widths and WinAnsi codes.  Be sure
# to pass these glyphs as UTF-8, and Prawn will transcode them for you.
#
require "#{File.dirname(__FILE__)}/../example_helper.rb"

FONT_SIZE = 9.5

Prawn::Document.generate("win-ansi.pdf") do
  @skip_encoding = true

  x = 0
  y = bounds.top

  fields = [[20, :right], [8, :left], [12, :center], [30, :right], [8, :left], [0, :left]]

  font "Helvetica", :size => FONT_SIZE

  Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
    next if name == ".notdef"
    y -= FONT_SIZE

    if y < FONT_SIZE
      y = bounds.top - FONT_SIZE
      x += 170
    end

    code = "%d." % index
    char = index.chr

    width = 1000 * width_of(char, :size => FONT_SIZE) / FONT_SIZE
    size = "%d" % width

    data = [code, nil, char, size, nil, name]
    dx = x
    fields.zip(data).each do |(total_width, align), field|
      if field
        width = width_of(field, :size => FONT_SIZE)

        case align
        when :left then offset = 0
        when :right then offset = total_width - width
        when :center then offset = (total_width - width)/2
        end

        draw_text(field, :at => [dx + offset, y])
      end

      dx += total_width
    end
  end
end

Version data entries

13 entries across 13 versions & 6 rubygems

Version Path
piglop-prawn-0.10.2.3 examples/m17n/win_ansi_charset.rb
piglop-prawn-0.10.2.2 examples/m17n/win_ansi_charset.rb
piglop-prawn-0.10.2.1 examples/m17n/win_ansi_charset.rb
prawn-0.11.1.pre examples/m17n/win_ansi_charset.rb
goodwill-prawn-edge-0.10.0 examples/m17n/win_ansi_charset.rb
alphasights-prawn-0.10.4 examples/m17n/win_ansi_charset.rb
alphasights-prawn-0.10.3 examples/m17n/win_ansi_charset.rb
alphasights-prawn-0.10.2 examples/m17n/win_ansi_charset.rb
alphasights-prawn-0.10.1 examples/m17n/win_ansi_charset.rb
alphasights-prawn-0.10.0 examples/m17n/win_ansi_charset.rb
prawn-core-0.8.4 examples/m17n/win_ansi_charset.rb
prawn-graph-0.0.2 vendor/prawn-core/examples/m17n/win_ansi_charset.rb
prawn-graph-0.0.1 vendor/prawn-core/examples/m17n/win_ansi_charset.rb