Class | Magick::RVG::Utility::GraphicContext |
In: |
lib/rvg/misc.rb
|
Parent: | Object |
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} |
gc | [R] | |
text_attrs | [R] |
# File lib/rvg/misc.rb, line 509 509: def GraphicContext.degrees_to_radians(deg) 510: Math::PI * (deg % 360.0) / 180.0 511: end
# File lib/rvg/misc.rb, line 537 537: def initialize() 538: @gc = Magick::Draw.new 539: @shadow = Array.new 540: @shadow << Magick::Draw.new 541: @text_attrs = TextAttributes.new 542: init_matrix() 543: end
# File lib/rvg/misc.rb, line 549 549: def affine(sx, rx, ry, sy, tx, ty) 550: sx, rx, ry, sy, tx, ty = Magick::RVG.convert_to_float(sx, rx, ry, sy, tx, ty) 551: @gc.affine(sx, rx, ry, sy, tx, ty) 552: @text_attrs.set_affine(sx, rx, ry, sy, tx, ty) 553: nil 554: end
# File lib/rvg/misc.rb, line 556 556: def baseline_shift(value) 557: @text_attrs.baseline_shift = case value 558: when 'baseline', 'sub', 'super' 559: value.intern 560: when /[-+]?\d+%/, Numeric 561: value 562: else 563: :baseline 564: end 565: nil 566: end
# File lib/rvg/misc.rb, line 568 568: def font(name) 569: @gc.font(name) 570: @shadow[-1].font = name 571: nil 572: end
# File lib/rvg/misc.rb, line 574 574: def font_family(name) 575: @gc.font_family(name) 576: @shadow[-1].font_family = name 577: nil 578: end
# File lib/rvg/misc.rb, line 580 580: def font_size(points) 581: @gc.font_size(points) 582: @shadow[-1].pointsize = points 583: nil 584: end
# File lib/rvg/misc.rb, line 586 586: def font_stretch(stretch) 587: stretch = FONT_STRETCH.fetch(stretch.intern, Magick::NormalStretch) 588: @gc.font_stretch(stretch) 589: @shadow[-1].font_stretch = stretch 590: nil 591: end
# File lib/rvg/misc.rb, line 593 593: def font_style(style) 594: style = FONT_STYLE.fetch(style.intern, Magick::NormalStyle) 595: @gc.font_style(style) 596: @shadow[-1].font_style = style 597: nil 598: end
# File lib/rvg/misc.rb, line 600 600: def font_weight(weight) 601: # If the arg is not in the hash use it directly. Handles numeric values. 602: weight = FONT_WEIGHT.fetch(weight) {|key| key} 603: @gc.font_weight(weight) 604: @shadow[-1].font_weight = weight 605: nil 606: end
# File lib/rvg/misc.rb, line 608 608: def glyph_orientation_horizontal(deg) 609: deg = Magick::RVG.convert_one_to_float(deg) 610: @text_attrs.glyph_orientation_horizontal = (deg % 360) / 90 * 90 611: nil 612: end
# File lib/rvg/misc.rb, line 614 614: def glyph_orientation_vertical(deg) 615: deg = Magick::RVG.convert_one_to_float(deg) 616: @text_attrs.glyph_orientation_vertical = (deg % 360) / 90 * 90 617: nil 618: end
# File lib/rvg/misc.rb, line 624 624: def letter_spacing(value) 625: @text_attrs.letter_spacing = Magick::RVG.convert_one_to_float(value) 626: nil 627: end
# File lib/rvg/misc.rb, line 545 545: def method_missing(methID, *args, &block) 546: @gc.__send__(methID, *args, &block) 547: end
# File lib/rvg/misc.rb, line 636 636: def pop() 637: @gc.pop 638: @shadow.pop 639: @text_attrs.pop 640: nil 641: end
# File lib/rvg/misc.rb, line 629 629: def push() 630: @gc.push 631: @shadow.push(@shadow.last.dup) 632: @text_attrs.push 633: nil 634: end
# File lib/rvg/misc.rb, line 643 643: def rotate(degrees) 644: degrees = Magick::RVG.convert_one_to_float(degrees) 645: @gc.rotate(degrees) 646: @sx = Math.cos(GraphicContext.degrees_to_radians(degrees)) 647: @rx = Math.sin(GraphicContext.degrees_to_radians(degrees)) 648: @ry = -Math.sin(GraphicContext.degrees_to_radians(degrees)) 649: @sy = Math.cos(GraphicContext.degrees_to_radians(degrees)) 650: concat_matrix() 651: nil 652: end
# File lib/rvg/misc.rb, line 654 654: def scale(sx, sy) 655: sx, sy = Magick::RVG.convert_to_float(sx, sy) 656: @gc.scale(sx, sy) 657: @sx, @sy = sx, sy 658: concat_matrix() 659: nil 660: end
# File lib/rvg/misc.rb, line 666 666: def skewX(degrees) 667: degrees = Magick::RVG.convert_one_to_float(degrees) 668: @gc.skewX(degrees) 669: @ry = Math.tan(GraphicContext.degrees_to_radians(degrees)) 670: concat_matrix() 671: nil 672: end
# File lib/rvg/misc.rb, line 674 674: def skewY(degrees) 675: degrees = Magick::RVG.convert_one_to_float(degrees) 676: @gc.skewY(degrees) 677: @rx = Math.tan(GraphicContext.degrees_to_radians(degrees)) 678: concat_matrix() 679: nil 680: end
# File lib/rvg/misc.rb, line 682 682: def stroke_width(width) 683: width = Magick::RVG.convert_one_to_float(width) 684: @gc.stroke_width(width) 685: @shadow[-1].stroke_width = width 686: nil 687: end
# File lib/rvg/misc.rb, line 689 689: def text(x, y, text) 690: return if text.length == 0 691: if @text_attrs.non_default? 692: text_renderer = TEXT_STRATEGIES[@text_attrs.writing_mode].new(self) 693: else 694: text_renderer = DefaultTextStrategy.new(self) 695: end 696: 697: return text_renderer.render(x, y, text) 698: end
# File lib/rvg/misc.rb, line 700 700: def text_anchor(anchor) 701: anchor = anchor.intern 702: anchor_enum = TEXT_ANCHOR.fetch(anchor, Magick::StartAnchor) 703: @gc.text_anchor(anchor_enum) 704: align = ANCHOR_TO_ALIGN.fetch(anchor, Magick::LeftAlign) 705: @shadow[-1].align = align 706: @text_attrs.text_anchor = anchor 707: nil 708: end
# File lib/rvg/misc.rb, line 710 710: def text_decoration(decoration) 711: decoration = TEXT_DECORATION.fetch(decoration.intern, Magick::NoDecoration) 712: @gc.decorate(decoration) 713: @shadow[-1].decorate = decoration 714: nil 715: end
# File lib/rvg/misc.rb, line 717 717: def translate(tx, ty) 718: tx, ty = Magick::RVG.convert_to_float(tx, ty) 719: @gc.translate(tx, ty) 720: @tx, @ty = tx, ty 721: concat_matrix() 722: nil 723: end
# File lib/rvg/misc.rb, line 725 725: def word_spacing(value) 726: @text_attrs.word_spacing = Magick::RVG.convert_one_to_float(value) 727: nil 728: end
# File lib/rvg/misc.rb, line 730 730: def writing_mode(mode) 731: @text_attrs.writing_mode = mode 732: nil 733: end
# File lib/rvg/misc.rb, line 521 521: def concat_matrix() 522: curr = @text_attrs.affine 523: sx = curr.sx * @sx + curr.ry * @rx 524: rx = curr.rx * @sx + curr.sy * @rx 525: ry = curr.sx * @ry + curr.ry * @sy 526: sy = curr.rx * @ry + curr.sy * @sy 527: tx = curr.sx * @tx + curr.ry * @ty + curr.tx 528: ty = curr.rx * @tx + curr.sy * @ty + curr.ty 529: @text_attrs.set_affine(sx, rx, ry, sy, tx, ty) 530: init_matrix() 531: end