Class: Magick::RVG::Utility::GraphicContext
- Inherits:
-
Object
- Object
- Magick::RVG::Utility::GraphicContext
- Defined in:
- lib/rvg/misc.rb
Overview
class TextAttributes
Constant Summary collapse
- 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 }.freeze
- FONT_STYLE =
{ normal: Magick::NormalStyle, italic: Magick::ItalicStyle, oblique: Magick::ObliqueStyle }.freeze
- FONT_WEIGHT =
{ normal: Magick::NormalWeight, bold: Magick::BoldWeight, bolder: Magick::BolderWeight, lighter: Magick::LighterWeight }.freeze
- TEXT_ANCHOR =
{ start: Magick::StartAnchor, middle: Magick::MiddleAnchor, end: Magick::EndAnchor }.freeze
- ANCHOR_TO_ALIGN =
{ start: Magick::LeftAlign, middle: Magick::CenterAlign, end: Magick::RightAlign }.freeze
- TEXT_DECORATION =
{ none: Magick::NoDecoration, underline: Magick::UnderlineDecoration, overline: Magick::OverlineDecoration, line_through: Magick::LineThroughDecoration }.freeze
- TEXT_STRATEGIES =
{ 'lr-tb' => LRTextStrategy, 'lr' => LRTextStrategy, 'rt-tb' => RLTextStrategy, 'rl' => RLTextStrategy, 'tb-rl' => TBTextStrategy, 'tb' => TBTextStrategy }.freeze
Instance Attribute Summary collapse
-
#gc ⇒ Object
readonly
Returns the value of attribute gc.
-
#text_attrs ⇒ Object
readonly
Returns the value of attribute text_attrs.
Class Method Summary collapse
Instance Method Summary collapse
- #affine(sx, rx, ry, sy, tx, ty) ⇒ Object
- #baseline_shift(value) ⇒ Object
- #font(name) ⇒ Object
- #font_family(name) ⇒ Object
- #font_size(points) ⇒ Object
- #font_stretch(stretch) ⇒ Object
- #font_style(style) ⇒ Object
- #font_weight(weight) ⇒ Object
- #glyph_orientation_horizontal(deg) ⇒ Object
- #glyph_orientation_vertical(deg) ⇒ Object
-
#initialize ⇒ GraphicContext
constructor
A new instance of GraphicContext.
- #inspect ⇒ Object
- #letter_spacing(value) ⇒ Object
- #method_missing(meth_id, *args) ⇒ Object
- #pop ⇒ Object
- #push ⇒ Object
- #rotate(degrees) ⇒ Object
- #scale(sx, sy) ⇒ Object
- #shadow ⇒ Object
- #skewX(degrees) ⇒ Object
- #skewY(degrees) ⇒ Object
- #stroke_width(width) ⇒ Object
- #text(x, y, text) ⇒ Object
- #text_anchor(anchor) ⇒ Object
- #text_decoration(decoration) ⇒ Object
- #translate(tx, ty) ⇒ Object
- #word_spacing(value) ⇒ Object
- #writing_mode(mode) ⇒ Object
Constructor Details
#initialize ⇒ GraphicContext
Returns a new instance of GraphicContext.
520 521 522 523 524 525 526 |
# File 'lib/rvg/misc.rb', line 520 def initialize @gc = Magick::Draw.new @shadow = [] @shadow << Magick::Draw.new @text_attrs = TextAttributes.new init_matrix end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth_id, *args) ⇒ Object
528 529 530 |
# File 'lib/rvg/misc.rb', line 528 def method_missing(meth_id, *args, &) @gc.__send__(meth_id, *args, &) end |
Instance Attribute Details
#gc ⇒ Object (readonly)
Returns the value of attribute gc.
518 519 520 |
# File 'lib/rvg/misc.rb', line 518 def gc @gc end |
#text_attrs ⇒ Object (readonly)
Returns the value of attribute text_attrs.
518 519 520 |
# File 'lib/rvg/misc.rb', line 518 def text_attrs @text_attrs end |
Class Method Details
.degrees_to_radians(deg) ⇒ Object
492 493 494 |
# File 'lib/rvg/misc.rb', line 492 def self.degrees_to_radians(deg) Math::PI * (deg % 360.0) / 180.0 end |
Instance Method Details
#affine(sx, rx, ry, sy, tx, ty) ⇒ Object
532 533 534 535 536 537 |
# File 'lib/rvg/misc.rb', line 532 def affine(sx, rx, ry, sy, tx, ty) sx, rx, ry, sy, tx, ty = Magick::RVG.convert_to_float(sx, rx, ry, sy, tx, ty) @gc.affine(sx, rx, ry, sy, tx, ty) @text_attrs.set_affine(sx, rx, ry, sy, tx, ty) nil end |
#baseline_shift(value) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/rvg/misc.rb', line 539 def baseline_shift(value) @text_attrs.baseline_shift = case value when 'baseline', 'sub', 'super' value.to_sym when /[-+]?\d+%/, Numeric value else :baseline end nil end |
#font(name) ⇒ Object
551 552 553 554 555 |
# File 'lib/rvg/misc.rb', line 551 def font(name) @gc.font(name) @shadow[-1].font = name nil end |
#font_family(name) ⇒ Object
557 558 559 560 561 |
# File 'lib/rvg/misc.rb', line 557 def font_family(name) @gc.font_family(name) @shadow[-1].font_family = name nil end |
#font_size(points) ⇒ Object
563 564 565 566 567 |
# File 'lib/rvg/misc.rb', line 563 def font_size(points) @gc.font_size(points) @shadow[-1].pointsize = points nil end |
#font_stretch(stretch) ⇒ Object
569 570 571 572 573 574 |
# File 'lib/rvg/misc.rb', line 569 def font_stretch(stretch) stretch = FONT_STRETCH.fetch(stretch.to_sym, Magick::NormalStretch) @gc.font_stretch(stretch) @shadow[-1].font_stretch = stretch nil end |
#font_style(style) ⇒ Object
576 577 578 579 580 581 |
# File 'lib/rvg/misc.rb', line 576 def font_style(style) style = FONT_STYLE.fetch(style.to_sym, Magick::NormalStyle) @gc.font_style(style) @shadow[-1].font_style = style nil end |
#font_weight(weight) ⇒ Object
583 584 585 586 587 588 589 |
# File 'lib/rvg/misc.rb', line 583 def font_weight(weight) # If the arg is not in the hash use it directly. Handles numeric values. weight = FONT_WEIGHT.fetch(weight.to_sym, Magick::NormalWeight) unless weight.is_a?(Numeric) @gc.font_weight(weight) @shadow[-1].font_weight = weight nil end |
#glyph_orientation_horizontal(deg) ⇒ Object
591 592 593 594 595 |
# File 'lib/rvg/misc.rb', line 591 def glyph_orientation_horizontal(deg) deg = Magick::RVG.convert_one_to_float(deg) @text_attrs.glyph_orientation_horizontal = (deg % 360) / 90 * 90 nil end |
#glyph_orientation_vertical(deg) ⇒ Object
597 598 599 600 601 |
# File 'lib/rvg/misc.rb', line 597 def glyph_orientation_vertical(deg) deg = Magick::RVG.convert_one_to_float(deg) @text_attrs.glyph_orientation_vertical = (deg % 360) / 90 * 90 nil end |
#inspect ⇒ Object
603 604 605 |
# File 'lib/rvg/misc.rb', line 603 def inspect @gc.inspect end |
#letter_spacing(value) ⇒ Object
607 608 609 610 |
# File 'lib/rvg/misc.rb', line 607 def letter_spacing(value) @text_attrs.letter_spacing = Magick::RVG.convert_one_to_float(value) nil end |
#pop ⇒ Object
619 620 621 622 623 624 |
# File 'lib/rvg/misc.rb', line 619 def pop @gc.pop @shadow.pop @text_attrs.pop nil end |
#push ⇒ Object
612 613 614 615 616 617 |
# File 'lib/rvg/misc.rb', line 612 def push @gc.push @shadow.push(@shadow.last.dup) @text_attrs.push nil end |
#rotate(degrees) ⇒ Object
626 627 628 629 630 631 632 633 634 635 |
# File 'lib/rvg/misc.rb', line 626 def rotate(degrees) degrees = Magick::RVG.convert_one_to_float(degrees) @gc.rotate(degrees) @sx = Math.cos(GraphicContext.degrees_to_radians(degrees)) @rx = Math.sin(GraphicContext.degrees_to_radians(degrees)) @ry = -Math.sin(GraphicContext.degrees_to_radians(degrees)) @sy = Math.cos(GraphicContext.degrees_to_radians(degrees)) concat_matrix nil end |
#scale(sx, sy) ⇒ Object
637 638 639 640 641 642 643 644 |
# File 'lib/rvg/misc.rb', line 637 def scale(sx, sy) sx, sy = Magick::RVG.convert_to_float(sx, sy) @gc.scale(sx, sy) @sx = sx @sy = sy concat_matrix nil end |
#shadow ⇒ Object
646 647 648 |
# File 'lib/rvg/misc.rb', line 646 def shadow @shadow.last end |
#skewX(degrees) ⇒ Object
650 651 652 653 654 655 656 |
# File 'lib/rvg/misc.rb', line 650 def skewX(degrees) degrees = Magick::RVG.convert_one_to_float(degrees) @gc.skewx(degrees) @ry = Math.tan(GraphicContext.degrees_to_radians(degrees)) concat_matrix nil end |
#skewY(degrees) ⇒ Object
658 659 660 661 662 663 664 |
# File 'lib/rvg/misc.rb', line 658 def skewY(degrees) degrees = Magick::RVG.convert_one_to_float(degrees) @gc.skewy(degrees) @rx = Math.tan(GraphicContext.degrees_to_radians(degrees)) concat_matrix nil end |
#stroke_width(width) ⇒ Object
666 667 668 669 670 671 |
# File 'lib/rvg/misc.rb', line 666 def stroke_width(width) width = Magick::RVG.convert_one_to_float(width) @gc.stroke_width(width) @shadow[-1].stroke_width = width nil end |
#text(x, y, text) ⇒ Object
673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/rvg/misc.rb', line 673 def text(x, y, text) return if text.empty? text_renderer = if @text_attrs.non_default? TEXT_STRATEGIES[@text_attrs.writing_mode].new(self) else DefaultTextStrategy.new(self) end text_renderer.render(x, y, text) end |
#text_anchor(anchor) ⇒ Object
685 686 687 688 689 690 691 692 693 |
# File 'lib/rvg/misc.rb', line 685 def text_anchor(anchor) anchor = anchor.to_sym anchor_enum = TEXT_ANCHOR.fetch(anchor, Magick::StartAnchor) @gc.text_anchor(anchor_enum) align = ANCHOR_TO_ALIGN.fetch(anchor, Magick::LeftAlign) @shadow[-1].align = align @text_attrs.text_anchor = anchor nil end |
#text_decoration(decoration) ⇒ Object
695 696 697 698 699 700 |
# File 'lib/rvg/misc.rb', line 695 def text_decoration(decoration) decoration = TEXT_DECORATION.fetch(decoration.to_sym, Magick::NoDecoration) @gc.decorate(decoration) @shadow[-1].decorate = decoration nil end |
#translate(tx, ty) ⇒ Object
702 703 704 705 706 707 708 709 |
# File 'lib/rvg/misc.rb', line 702 def translate(tx, ty) tx, ty = Magick::RVG.convert_to_float(tx, ty) @gc.translate(tx, ty) @tx = tx @ty = ty concat_matrix nil end |
#word_spacing(value) ⇒ Object
711 712 713 714 |
# File 'lib/rvg/misc.rb', line 711 def word_spacing(value) @text_attrs.word_spacing = Magick::RVG.convert_one_to_float(value) nil end |
#writing_mode(mode) ⇒ Object
716 717 718 719 |
# File 'lib/rvg/misc.rb', line 716 def writing_mode(mode) @text_attrs.writing_mode = mode nil end |