Class: Docxi::Word::Headers::Header::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/docxi/word/headers/header.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(media, options = {}) ⇒ Image

Returns a new instance of Image.



75
76
77
78
79
# File 'lib/docxi/word/headers/header.rb', line 75

def initialize(media, options={})
  @media = media
  # @media.file.rewind
  @options = options
end

Instance Attribute Details

#mediaObject

Returns the value of attribute media.



74
75
76
# File 'lib/docxi/word/headers/header.rb', line 74

def media
  @media
end

#optionsObject

Returns the value of attribute options.



74
75
76
# File 'lib/docxi/word/headers/header.rb', line 74

def options
  @options
end

Instance Method Details

#heightObject



85
86
87
# File 'lib/docxi/word/headers/header.rb', line 85

def height
  @options[:height]
end

#render(xml) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/docxi/word/headers/header.rb', line 89

def render(xml)
  xml['w'].p do
    xml['w'].pPr do
      xml['w'].jc( 'w:val' => @options[:align] ) if @options[:align]
    end
    xml['w'].r do
      xml['w'].rPr do
        xml['w'].noProof
      end
      xml['w'].drawing do
        xml['wp'].anchor( "behindDoc" => options[:behind] ,"distT" => 0,"distB" => 0, "distL" => 0, "distR" => 0 ,"simplePos" => 0 ,"locked" => 0, "layoutInCell" => 1, "allowOverlap" => 1, "relativeHeight" => 4) do
          xml['wp'].simplePos('x'=> 0 , 'y' => 0 )
          xml['wp'].positionH("relativeFrom" => "column") do
            xml['wp'].posOffset options[:pH] 
          end
          xml['wp'].positionV("relativeFrom" => "paragraph") do
            xml['wp'].posOffset options[:pV] 
          end
          xml['wp'].extent( 'cx' => ( options[:width] * options[:height] * 14.92 ).to_i, 'cy' => ( options[:width] * options[:height] * 14.92 ).to_i ) if options[:width] && options[:height]
          xml['wp'].effectExtent( 'l' => 0, 't' => 0, 'r' => 0, 'b' => 0 )
          if options[:wrap] == "none"
            xml['wp'].wrapNone
          else
            xml['wp'].wrapSquare("wrapText"=> "bothSides")
          end
          xml['wp'].docPr( 'id' => 1, 'name'=> "Image", 'descr' => "image")
          xml['wp'].cNvGraphicFramePr do
            xml.graphicFrameLocks( 'xmlns:a' => "http://schemas.openxmlformats.org/drawingml/2006/main", 'noChangeAspect' => "1" ) do
              xml.parent.namespace = xml.parent.namespace_definitions.find{|ns| ns.prefix == "a" }
            end
          end
          xml.graphic( 'xmlns:a' => "http://schemas.openxmlformats.org/drawingml/2006/main" ) do
            xml.parent.namespace = xml.parent.namespace_definitions.find{|ns| ns.prefix == "a" }
            xml['a'].graphicData( 'uri' => "http://schemas.openxmlformats.org/drawingml/2006/picture") do
              xml.pic( 'xmlns:pic' => "http://schemas.openxmlformats.org/drawingml/2006/picture") do
                xml.parent.namespace = xml.parent.namespace_definitions.find{|ns| ns.prefix == "pic" }
                xml['pic'].nvPicPr do
                  xml['pic'].cNvPr( 'id' => 0, 'name' => "Image" )
                  xml['pic'].cNvPicPr 
                end
                xml['pic'].blipFill do
                  xml['a'].blip( 'r:embed' => @media.sequence ) do
                    xml['a'].extLst
                  end
                  xml['a'].stretch do
                    xml['a'].fillRect
                  end
                end
                xml['pic'].spPr( 'bwMode' => "auto" ) do
                  xml['a'].xfrm do
                    xml['a'].off( 'x' => 0, 'y' => 0 )
                    xml['a'].ext( 'cx' => ( options[:width] * options[:height] * 14.92 ).to_i, 'cy' => ( options[:width] * options[:height] * 14.92).to_i ) if options[:width] && options[:height]
                  end
                  xml['a'].prstGeom( 'prst' => "rect" ) do
                    xml['a'].avLst
                  end
                  # xml['a'].noFill
                  # xml['a'].ln('w' => "9525") do
                  #   xml['a'].noFill
                  #   xml['a'].miter('lim'=>"800000")
                  #   xml['a'].headEnd
                  #   xml['a'].tailEnd
                  # end
                end
              end
            end
          end
        end
      end
    end
  end
end

#widthObject



81
82
83
# File 'lib/docxi/word/headers/header.rb', line 81

def width
  @options[:width]
end