Class: Magick::RVG::Utility::TextStrategy

### Home Classes Methods

### In Files

- lib/rvg/misc.rb

### Parent

Object

### Methods

- ::new
- #enquote
- #glyph_metrics
- #render_glyph
- #shift_baseline
- #text_rel_coords

### Files

- MANIFEST
- Makefile

### Class/Module Index

Quicksearch

- Magick
- Magick::DestroyedImageError
- Magick::Draw
- Magick::Enum
- Magick::FatalImageMagickError
- Magick::Geometry
- Magick::GeometryValue
- Magick::GradientFill
- Magick::HatchFill
- Magick::IPTC
- Magick::IPTC::Application
- Magick::IPTC::Envelope
- Magick::IPTC::ObjectData
- Magick::IPTC::Post_ObjectData_Descriptor
- Magick::IPTC::Pre_ObjectData_Descriptor
- Magick::Image
- Magick::Image::DrawOptions
- Magick::Image::Info
- Magick::Image::PolaroidOptions
- Magick::Image::View
- Magick::Image::View::Pixels
- Magick::Image::View::Rows
- Magick::ImageList
- Magick::ImageList::Montage
- Magick::ImageMagickError
- Magick::OptionalMethodArguments
- Magick::Pixel
- Magick::RVG
- Magick::RVG::Circle
- Magick::RVG::ClipPath
- Magick::RVG::Describable
- Magick::RVG::Duplicatable
- Magick::RVG::Ellipse
- Magick::RVG::Embellishable
- Magick::RVG::Group
- Magick::RVG::Image
- Magick::RVG::ImageConstructors
- Magick::RVG::Line
- Magick::RVG::Path
- Magick::RVG::PathData
- Magick::RVG::Pattern
- Magick::RVG::PolyShape
- Magick::RVG::Polygon
- Magick::RVG::Polyline
- Magick::RVG::PreserveAspectRatio
- Magick::RVG::Rect
- Magick::RVG::ShapeConstructors
- Magick::RVG::Stretchable
- Magick::RVG::StructureConstructors
- Magick::RVG::Stylable
- Magick::RVG::Text
- Magick::RVG::TextBase
- Magick::RVG::TextConstructors
- Magick::RVG::Transformable
- Magick::RVG::Use
- Magick::RVG::UseConstructors
- Magick::RVG::Utility
- Magick::RVG::Utility::DefaultTextStrategy
- Magick::RVG::Utility::GraphicContext
- Magick::RVG::Utility::LRTextStrategy
- Magick::RVG::Utility::RLTextStrategy
- Magick::RVG::Utility::TBTextStrategy
- Magick::RVG::Utility::TextAttributes
- Magick::RVG::Utility::TextStrategy
- Magick::TextureFill
- Object

No matching classes.

# Magick::RVG::Utility::TextStrategy

### Public Class Methods

new(context) click to toggle source

    # File lib/rvg/misc.rb, line 82
    def initialize(context)
        @ctx = context
        @ctx.shadow.affine = @ctx.text_attrs.affine
    end

### Public Instance Methods

enquote(text) click to toggle source

    # File lib/rvg/misc.rb, line 87
    def enquote(text)
        if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
            return text
        elsif !text['\']
            text = '\'+text+'\'
            return text
        elsif !text['"']
            text = '"'+text+'"'
            return text
        elsif !(text['{'] || text['}'])
            text = '{'+text+'}'
            return text
        end

        # escape existing braces, surround with braces
        text.gsub!(/[}]/) { |b| '\' + b }
        return '{' +  text + '}'
    end

glyph_metrics(glyph_orientation, glyph) click to toggle source

    # File lib/rvg/misc.rb, line 106
    def glyph_metrics(glyph_orientation, glyph)
        gm = @ctx.shadow.get_type_metrics("a" + glyph + "a")
        gm2 = @ctx.shadow.get_type_metrics("aa")
        h = (gm.ascent - gm.descent + 0.5 ).to_i
        w = gm.width - gm2.width
        if glyph_orientation == 0 || glyph_orientation == 180
            [w, h]
        else
            [h, w]
        end
    end

render_glyph(glyph_orientation, x, y, glyph) click to toggle source

    # File lib/rvg/misc.rb, line 162
    def render_glyph(glyph_orientation, x, y, glyph)
        if glyph_orientation == 0
            @ctx.gc.text(x, y, enquote(glyph))
        else
            @ctx.gc.push
            @ctx.gc.translate(x, y)
            @ctx.gc.rotate(glyph_orientation)
            @ctx.gc.translate(-x, -y)
            @ctx.gc.text(x, y, enquote(glyph))
            @ctx.gc.pop
        end
    end

shift_baseline(glyph_orientation, glyph) click to toggle source

    # File lib/rvg/misc.rb, line 139
    def shift_baseline(glyph_orientation, glyph)
        glyph_dimensions = @ctx.shadow.get_type_metrics(glyph)
        if glyph_orientation == 0 || glyph_orientation == 180
            x = glyph_dimensions.width
        else
            x = glyph_dimensions.ascent - glyph_dimensions.descent
        end
        case @ctx.text_attrs.baseline_shift
            when :baseline
                x = 0
            when :sub
                ;
            when :super
                x = -x
            when /[-+]?(\d+)%/
                m = $1 == '-' ? -1.0 : 1.0
                x = (m * x * $1.to_f / 100.0)
            else
                x = -@ctx.text_attrs.baseline_shift
        end
        return x
    end

text_rel_coords(text) click to toggle source

    # File lib/rvg/misc.rb, line 118
    def text_rel_coords(text)
        y_rel_coords = []
        x_rel_coords = []
        first_word = true
        words = text.split(::Magick::RVG::WORD_SEP)
        words.each do |word|
            unless first_word
                wx, wy = get_word_spacing()
                x_rel_coords << wx
                y_rel_coords << wy
            end
            first_word = false
            word.split('').each do |glyph|
                wx, wy = get_letter_spacing(glyph)
                x_rel_coords << wx
                y_rel_coords << wy
            end
        end
        [x_rel_coords, y_rel_coords]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.