Class Magick::RVG::Utility::GraphicContext
In: lib/rvg/misc.rb
Parent: Object
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Enumerable Geometry HatchFill Draw lib/RMagick.rb lib/rvg/rvg.rb ObjectData Application Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

Methods

Constants

FONT_STRETCH = {:normal => Magick::NormalStretch, :ultra_condensed => Magick::UltraCondensedStretch, :extra_condensed => Magick::ExtraCondensedStretch, :condensed => Magick::CondensedStretch, :semi_condensed => Magick::SemiCondensedStretch, :semi_expanded => Magick::SemiExpandedStretch, :expanded => Magick::ExpandedStretch, :extra_expanded => Magick::ExtraExpandedStretch, :ultra_expanded => Magick::UltraExpandedStretch}
FONT_STYLE = {:normal => Magick::NormalStyle, :italic => Magick::ItalicStyle, :oblique => Magick::ObliqueStyle}
FONT_WEIGHT = {'normal' => Magick::NormalWeight, 'bold' => Magick::BoldWeight, 'bolder' => Magick::BolderWeight, 'lighter' => Magick::LighterWeight}
TEXT_ANCHOR = {:start => Magick::StartAnchor, :middle => Magick::MiddleAnchor, :end => Magick::EndAnchor}
ANCHOR_TO_ALIGN = {:start => Magick::LeftAlign, :middle => Magick::CenterAlign, :end => Magick::RightAlign}
TEXT_DECORATION = {:none => Magick::NoDecoration, :underline => Magick::UnderlineDecoration, :overline => Magick::OverlineDecoration, :line_through => Magick::LineThroughDecoration}
TEXT_STRATEGIES = {'lr-tb'=>LRTextStrategy, 'lr'=>LRTextStrategy, 'rt-tb'=>RLTextStrategy, 'rl'=>RLTextStrategy, 'tb-rl'=>TBTextStrategy, 'tb'=>TBTextStrategy}

Attributes

gc  [R] 
text_attrs  [R] 

Public Class methods

[Source]

     # File lib/rvg/misc.rb, line 508
508:                 def GraphicContext.degrees_to_radians(deg)
509:                     Math::PI * (deg % 360.0) / 180.0
510:                 end

[Source]

     # File lib/rvg/misc.rb, line 536
536:                 def initialize()
537:                     @gc = Magick::Draw.new
538:                     @shadow = Array.new
539:                     @shadow << Magick::Draw.new
540:                     @text_attrs = TextAttributes.new
541:                     init_matrix()
542:                 end

Public Instance methods

[Source]

     # File lib/rvg/misc.rb, line 548
548:                 def affine(sx, rx, ry, sy, tx, ty)
549:                     sx, rx, ry, sy, tx, ty = Magick::RVG.convert_to_float(sx, rx, ry, sy, tx, ty)
550:                     @gc.affine(sx, rx, ry, sy, tx, ty)
551:                     @text_attrs.set_affine(sx, rx, ry, sy, tx, ty)
552:                     nil
553:                 end

[Source]

     # File lib/rvg/misc.rb, line 555
555:                 def baseline_shift(value)
556:                     @text_attrs.baseline_shift = case value
557:                         when 'baseline', 'sub', 'super'
558:                             value.intern
559:                         when /[-+]?\d+%/, Numeric
560:                             value
561:                         else
562:                             :baseline
563:                         end
564:                     nil
565:                 end

[Source]

     # File lib/rvg/misc.rb, line 567
567:                 def font(name)
568:                     @gc.font(name)
569:                     @shadow[-1].font = name
570:                     nil
571:                 end

[Source]

     # File lib/rvg/misc.rb, line 573
573:                 def font_family(name)
574:                     @gc.font_family(name)
575:                     @shadow[-1].font_family = name
576:                     nil
577:                 end

[Source]

     # File lib/rvg/misc.rb, line 579
579:                 def font_size(points)
580:                     @gc.font_size(points)
581:                     @shadow[-1].pointsize = points
582:                     nil
583:                 end

[Source]

     # File lib/rvg/misc.rb, line 585
585:                 def font_stretch(stretch)
586:                     stretch = FONT_STRETCH.fetch(stretch.intern, Magick::NormalStretch)
587:                     @gc.font_stretch(stretch)
588:                     @shadow[-1].font_stretch = stretch
589:                     nil
590:                 end

[Source]

     # File lib/rvg/misc.rb, line 592
592:                 def font_style(style)
593:                     style = FONT_STYLE.fetch(style.intern, Magick::NormalStyle)
594:                     @gc.font_style(style)
595:                     @shadow[-1].font_style = style
596:                     nil
597:                 end

[Source]

     # File lib/rvg/misc.rb, line 599
599:                 def font_weight(weight)
600:                     # If the arg is not in the hash use it directly. Handles numeric values.
601:                     weight = FONT_WEIGHT.fetch(weight) {|key| key}
602:                     @gc.font_weight(weight)
603:                     @shadow[-1].font_weight = weight
604:                     nil
605:                 end

[Source]

     # File lib/rvg/misc.rb, line 607
607:                 def glyph_orientation_horizontal(deg)
608:                     deg = Magick::RVG.convert_one_to_float(deg)
609:                     @text_attrs.glyph_orientation_horizontal = (deg % 360) / 90 * 90
610:                     nil
611:                 end

[Source]

     # File lib/rvg/misc.rb, line 613
613:                 def glyph_orientation_vertical(deg)
614:                     deg = Magick::RVG.convert_one_to_float(deg)
615:                     @text_attrs.glyph_orientation_vertical = (deg % 360) / 90 * 90
616:                     nil
617:                 end

[Source]

     # File lib/rvg/misc.rb, line 619
619:                 def inspect()
620:                     @gc.inspect
621:                 end

[Source]

     # File lib/rvg/misc.rb, line 623
623:                 def letter_spacing(value)
624:                     @text_attrs.letter_spacing = Magick::RVG.convert_one_to_float(value)
625:                     nil
626:                 end

[Source]

     # File lib/rvg/misc.rb, line 544
544:                 def method_missing(methID, *args, &block)
545:                     @gc.__send__(methID, *args, &block)
546:                 end

[Source]

     # File lib/rvg/misc.rb, line 635
635:                 def pop()
636:                     @gc.pop
637:                     @shadow.pop
638:                     @text_attrs.pop
639:                     nil
640:                 end

[Source]

     # File lib/rvg/misc.rb, line 628
628:                 def push()
629:                     @gc.push
630:                     @shadow.push(@shadow.last.dup)
631:                     @text_attrs.push
632:                     nil
633:                 end

[Source]

     # File lib/rvg/misc.rb, line 642
642:                 def rotate(degrees)
643:                     degrees = Magick::RVG.convert_one_to_float(degrees)
644:                     @gc.rotate(degrees)
645:                     @sx =  Math.cos(GraphicContext.degrees_to_radians(degrees))
646:                     @rx =  Math.sin(GraphicContext.degrees_to_radians(degrees))
647:                     @ry = -Math.sin(GraphicContext.degrees_to_radians(degrees))
648:                     @sy =  Math.cos(GraphicContext.degrees_to_radians(degrees))
649:                     concat_matrix()
650:                     nil
651:                 end

[Source]

     # File lib/rvg/misc.rb, line 653
653:                 def scale(sx, sy)
654:                     sx, sy = Magick::RVG.convert_to_float(sx, sy)
655:                     @gc.scale(sx, sy)
656:                     @sx, @sy = sx, sy
657:                     concat_matrix()
658:                     nil
659:                 end

[Source]

     # File lib/rvg/misc.rb, line 661
661:                 def shadow()
662:                     @shadow.last
663:                 end

[Source]

     # File lib/rvg/misc.rb, line 665
665:                 def skewX(degrees)
666:                     degrees = Magick::RVG.convert_one_to_float(degrees)
667:                     @gc.skewX(degrees)
668:                     @ry = Math.tan(GraphicContext.degrees_to_radians(degrees))
669:                     concat_matrix()
670:                     nil
671:                 end

[Source]

     # File lib/rvg/misc.rb, line 673
673:                 def skewY(degrees)
674:                     degrees = Magick::RVG.convert_one_to_float(degrees)
675:                     @gc.skewY(degrees)
676:                     @rx = Math.tan(GraphicContext.degrees_to_radians(degrees))
677:                     concat_matrix()
678:                     nil
679:                 end

[Source]

     # File lib/rvg/misc.rb, line 681
681:                 def stroke_width(width)
682:                     width = Magick::RVG.convert_one_to_float(width)
683:                     @gc.stroke_width(width)
684:                     @shadow[-1].stroke_width = width
685:                     nil
686:                 end

[Source]

     # File lib/rvg/misc.rb, line 688
688:                 def text(x, y, text)
689:                     return if text.length == 0
690:                     if @text_attrs.non_default?
691:                         text_renderer = TEXT_STRATEGIES[@text_attrs.writing_mode].new(self)
692:                     else
693:                         text_renderer = DefaultTextStrategy.new(self)
694:                     end
695: 
696:                     return text_renderer.render(x, y, text)
697:                 end

[Source]

     # File lib/rvg/misc.rb, line 699
699:                 def text_anchor(anchor)
700:                     anchor = anchor.intern
701:                     anchor_enum = TEXT_ANCHOR.fetch(anchor, Magick::StartAnchor)
702:                     @gc.text_anchor(anchor_enum)
703:                     align = ANCHOR_TO_ALIGN.fetch(anchor, Magick::LeftAlign)
704:                     @shadow[-1].align = align
705:                     @text_attrs.text_anchor = anchor
706:                     nil
707:                 end

[Source]

     # File lib/rvg/misc.rb, line 709
709:                 def text_decoration(decoration)
710:                     decoration = TEXT_DECORATION.fetch(decoration.intern, Magick::NoDecoration)
711:                     @gc.decorate(decoration)
712:                     @shadow[-1].decorate = decoration
713:                     nil
714:                 end

[Source]

     # File lib/rvg/misc.rb, line 716
716:                 def translate(tx, ty)
717:                     tx, ty = Magick::RVG.convert_to_float(tx, ty)
718:                     @gc.translate(tx, ty)
719:                     @tx, @ty = tx, ty
720:                     concat_matrix()
721:                     nil
722:                 end

[Source]

     # File lib/rvg/misc.rb, line 724
724:                 def word_spacing(value)
725:                     @text_attrs.word_spacing = Magick::RVG.convert_one_to_float(value)
726:                     nil
727:                 end

[Source]

     # File lib/rvg/misc.rb, line 729
729:                 def writing_mode(mode)
730:                     @text_attrs.writing_mode = mode
731:                     nil
732:                 end

Private Instance methods

[Source]

     # File lib/rvg/misc.rb, line 520
520:                 def concat_matrix()
521:                     curr = @text_attrs.affine
522:                     sx = curr.sx * @sx + curr.ry * @rx
523:                     rx = curr.rx * @sx + curr.sy * @rx
524:                     ry = curr.sx * @ry + curr.ry * @sy
525:                     sy = curr.rx * @ry + curr.sy * @sy
526:                     tx = curr.sx * @tx + curr.ry * @ty + curr.tx
527:                     ty = curr.rx * @tx + curr.sy * @ty + curr.ty
528:                     @text_attrs.set_affine(sx, rx, ry, sy, tx, ty)
529:                     init_matrix()
530:                 end

[Source]

     # File lib/rvg/misc.rb, line 514
514:                 def init_matrix()
515:                     @rx = @ry = 0
516:                     @sx = @sy = 1
517:                     @tx = @ty = 0
518:                 end

[Validate]