Sha256: ed0204c1b874f42f1eae67fafbfe42ff50fac82a85b3272c332275231265f2ca

Contents?: true

Size: 1.81 KB

Versions: 7

Compression:

Stored size: 1.81 KB

Contents

#--
# PDF::Writer for Ruby.
#   http://rubyforge.org/projects/ruby-pdf/
#   Copyright 2003 - 2005 Austin Ziegler.
#
#   Licensed under a MIT-style licence. See LICENCE in the main distribution
#   for full licensing information.
#
# The code in this file is highly experimental and is not generally ready
# for use. I can't figure out why the stuff *after* is so far to the right.
# I'll need to play with the X position some to get it right. This will NOT
# make it into the 1.0 release. Maybe 1.1 or 1.2.
#
# $Id$
#++
begin
  require 'pdf/writer'
rescue LoadError => le
  if le.message =~ %r{pdf/writer$}
    $LOAD_PATH.unshift("../lib")
    require 'pdf/writer'
  else
    raise
  end
end

pdf = PDF::Writer.new
pdf.select_font "Times-Roman"

class TagCodeFont
  FONT_NAME       = "Courier"
  FONT_ENCODING   = nil
  FONT_SIZE_DIFF  = 0.9

  class << self
    attr_accessor :font_name

    def [](pdf, info)
      @font_name          ||= FONT_NAME
      @font_encoding      ||= FONT_ENCODING

      case info[:status]
      when :start, :start_line
        @__fontinfo ||= {}
        @__fontinfo[info[:cbid]] = {
          :font       => pdf.current_font,
          :base_font  => pdf.current_base_font,
          :info       => info
        }

        pdf.select_font(@font_name, @font_encoding)

        { :font_change => true }
      when :end, :end_line
        fi = @__fontinfo[info[:cbid]]

        pdf.font_size = fi[:font_size]
        pdf.select_font(fi[:base_font])
        pdf.select_font(fi[:font])
      end
    end
  end
end

PDF::Writer::TAGS[:pair]["code"] = TagCodeFont

pdf.text "Hello, <c:code>Ruby</c:code>.", :font_size => 72, :justification => :center
pdf.move_pointer(80)
pdf.text "This is a longer <c:code>sample of code font text</c:code>. What do you think?", :font_size => 12, :justification => :full

pdf.save_as("code.pdf")

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
ypdf-writer-1.3.5 demo/code.rb
ypdf-writer-1.3.3 demo/code.rb
ypdf-writer-1.3.2 demo/code.rb
metaskills-pdf-writer-1.2.2 demo/code.rb
metaskills-pdf-writer-1.2.3 demo/code.rb
eventioz-pdf-writer-1.2.4 demo/code.rb
eventioz-pdf-writer-1.0 demo/code.rb