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 Array Geometry HatchFill Draw lib/RMagick.rb lib/rvg/rvg.rb Magick Module: Magick

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 500
500:         def GraphicContext.degrees_to_radians(deg)
501:             Math::PI * (deg % 360.0) / 180.0
502:         end

[Source]

     # File lib/rvg/misc.rb, line 528
528:         def initialize()
529:             @gc = Magick::Draw.new
530:             @shadow = Array.new
531:             @shadow << Magick::Draw.new
532:             @text_attrs = TextAttributes.new
533:             init_matrix()
534:         end

Public Instance methods

[Source]

     # File lib/rvg/misc.rb, line 540
540:         def affine(sx, rx, ry, sy, tx, ty)
541:             sx, rx, ry, sy, tx, ty = Magick::RVG.convert_to_float(sx, rx, ry, sy, tx, ty)
542:             @gc.affine(sx, rx, ry, sy, tx, ty)
543:             @text_attrs.set_affine(sx, rx, ry, sy, tx, ty)
544:             nil
545:         end

[Source]

     # File lib/rvg/misc.rb, line 547
547:         def baseline_shift(value)
548:             @text_attrs.baseline_shift = case value
549:                 when 'baseline', 'sub', 'super'
550:                     value.intern
551:                 when /[-+]?\d+%/, Numeric
552:                     value
553:                 else
554:                     :baseline
555:                 end
556:             nil
557:         end

[Source]

     # File lib/rvg/misc.rb, line 559
559:         def font(name)
560:             @gc.font(name)
561:             @shadow[-1].font = name
562:             nil
563:         end

[Source]

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

[Source]

     # File lib/rvg/misc.rb, line 571
571:         def font_size(points)
572:             @gc.font_size(points)
573:             @shadow[-1].pointsize = points
574:             nil
575:         end

[Source]

     # File lib/rvg/misc.rb, line 577
577:         def font_stretch(stretch)
578:             stretch = FONT_STRETCH.fetch(stretch.intern, Magick::NormalStretch)
579:             @gc.font_stretch(stretch)
580:             @shadow[-1].font_stretch = stretch
581:             nil
582:         end

[Source]

     # File lib/rvg/misc.rb, line 584
584:         def font_style(style)
585:             style = FONT_STYLE.fetch(style.intern, Magick::NormalStyle)
586:             @gc.font_style(style)
587:             @shadow[-1].font_style = style
588:             nil
589:         end

[Source]

     # File lib/rvg/misc.rb, line 591
591:         def font_weight(weight)
592:             # If the arg is not in the hash use it directly. Handles numeric values.
593:             weight = FONT_WEIGHT.fetch(weight) {|key| key}
594:             @gc.font_weight(weight)
595:             @shadow[-1].font_weight = weight
596:             nil
597:         end

[Source]

     # File lib/rvg/misc.rb, line 599
599:         def glyph_orientation_horizontal(deg)
600:             deg = Magick::RVG.convert_one_to_float(deg)
601:             @text_attrs.glyph_orientation_horizontal = (deg % 360) / 90 * 90
602:             nil
603:         end

[Source]

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

[Source]

     # File lib/rvg/misc.rb, line 611
611:         def inspect()
612:             @gc.inspect
613:         end

[Source]

     # File lib/rvg/misc.rb, line 615
615:         def letter_spacing(value)
616:             @text_attrs.letter_spacing = Magick::RVG.convert_one_to_float(value)
617:             nil
618:         end

[Source]

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

[Source]

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

[Source]

     # File lib/rvg/misc.rb, line 620
620:         def push()
621:             @gc.push
622:             @shadow.push(@shadow.last.dup)
623:             @text_attrs.push
624:             nil
625:         end

[Source]

     # File lib/rvg/misc.rb, line 634
634:         def rotate(degrees)
635:             degrees = Magick::RVG.convert_one_to_float(degrees)
636:             @gc.rotate(degrees)
637:             @sx =  Math.cos(GraphicContext.degrees_to_radians(degrees))
638:             @rx =  Math.sin(GraphicContext.degrees_to_radians(degrees))
639:             @ry = -Math.sin(GraphicContext.degrees_to_radians(degrees))
640:             @sy =  Math.cos(GraphicContext.degrees_to_radians(degrees))
641:             concat_matrix()
642:             nil
643:         end

[Source]

     # File lib/rvg/misc.rb, line 645
645:         def scale(sx, sy)
646:             sx, sy = Magick::RVG.convert_to_float(sx, sy)
647:             @gc.scale(sx, sy)
648:             @sx, @sy = sx, sy
649:             concat_matrix()
650:             nil
651:         end

[Source]

     # File lib/rvg/misc.rb, line 653
653:         def shadow()
654:             @shadow.last
655:         end

[Source]

     # File lib/rvg/misc.rb, line 657
657:         def skewX(degrees)
658:             degrees = Magick::RVG.convert_one_to_float(degrees)
659:             @gc.skewX(degrees)
660:             @ry = Math.tan(GraphicContext.degrees_to_radians(degrees))
661:             concat_matrix()
662:             nil
663:         end

[Source]

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

[Source]

     # File lib/rvg/misc.rb, line 673
673:         def stroke_width(width)
674:             width = Magick::RVG.convert_one_to_float(width)
675:             @gc.stroke_width(width)
676:             @shadow[-1].stroke_width = width
677:             nil
678:         end

[Source]

     # File lib/rvg/misc.rb, line 680
680:         def text(x, y, text)
681:             return if text.length == 0
682:             if @text_attrs.non_default?
683:                 text_renderer = TEXT_STRATEGIES[@text_attrs.writing_mode].new(self)
684:             else
685:                 text_renderer = DefaultTextStrategy.new(self)
686:             end
687: 
688:             return text_renderer.render(x, y, text)
689:         end

[Source]

     # File lib/rvg/misc.rb, line 691
691:         def text_anchor(anchor)
692:             anchor = anchor.intern
693:             anchor_enum = TEXT_ANCHOR.fetch(anchor, Magick::StartAnchor)
694:             @gc.text_anchor(anchor_enum)
695:             align = ANCHOR_TO_ALIGN.fetch(anchor, Magick::LeftAlign)
696:             @shadow[-1].align = align
697:             @text_attrs.text_anchor = anchor
698:             nil
699:         end

[Source]

     # File lib/rvg/misc.rb, line 701
701:         def text_decoration(decoration)
702:             decoration = TEXT_DECORATION.fetch(decoration.intern, Magick::NoDecoration)
703:             @gc.decorate(decoration)
704:             @shadow[-1].decorate = decoration
705:             nil
706:         end

[Source]

     # File lib/rvg/misc.rb, line 708
708:         def translate(tx, ty)
709:             tx, ty = Magick::RVG.convert_to_float(tx, ty)
710:             @gc.translate(tx, ty)
711:             @tx, @ty = tx, ty
712:             concat_matrix()
713:             nil
714:         end

[Source]

     # File lib/rvg/misc.rb, line 716
716:         def word_spacing(value)
717:             @text_attrs.word_spacing = Magick::RVG.convert_one_to_float(value)
718:             nil
719:         end

[Source]

     # File lib/rvg/misc.rb, line 721
721:         def writing_mode(mode)
722:             @text_attrs.writing_mode = mode
723:             nil
724:         end

Private Instance methods

[Source]

     # File lib/rvg/misc.rb, line 512
512:         def concat_matrix()
513:             curr = @text_attrs.affine
514:             sx = curr.sx * @sx + curr.ry * @rx
515:             rx = curr.rx * @sx + curr.sy * @rx
516:             ry = curr.sx * @ry + curr.ry * @sy
517:             sy = curr.rx * @ry + curr.sy * @sy
518:             tx = curr.sx * @tx + curr.ry * @ty + curr.tx
519:             ty = curr.rx * @tx + curr.sy * @ty + curr.ty
520:             @text_attrs.set_affine(sx, rx, ry, sy, tx, ty)
521:             init_matrix()
522:         end

[Source]

     # File lib/rvg/misc.rb, line 506
506:         def init_matrix()
507:             @rx = @ry = 0
508:             @sx = @sy = 1
509:             @tx = @ty = 0
510:         end

[Validate]