Class: OpenXml::Docx::Package
- Inherits:
-
Package
- Object
- Package
- OpenXml::Docx::Package
- Defined in:
- lib/openxml/docx/package.rb
Instance Attribute Summary collapse
-
#doc_rels ⇒ Object
readonly
Returns the value of attribute doc_rels.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#font_rels ⇒ Object
readonly
Returns the value of attribute font_rels.
-
#fonts ⇒ Object
readonly
Returns the value of attribute fonts.
-
#footers ⇒ Object
readonly
Returns the value of attribute footers.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Method Summary collapse
- #add_footer(footer) ⇒ Object
- #add_header(header) ⇒ Object
- #embed_truetype_font(path: nil, name: nil) ⇒ Object
-
#initialize ⇒ Package
constructor
A new instance of Package.
Constructor Details
#initialize ⇒ Package
Returns a new instance of Package.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/openxml/docx/package.rb', line 23 def initialize super rels.add_relationship REL_DOCUMENT, "/word/document.xml" @doc_rels = OpenXml::Parts::Rels.new @font_rels = OpenXml::Parts::Rels.new @settings = OpenXml::Docx::Parts::Settings.new @styles = OpenXml::Docx::Parts::Styles.new @fonts = OpenXml::Docx::Parts::Fonts.new @document = OpenXml::Docx::Parts::Document.new @headers = [] @footers = [] doc_rels.add_relationship REL_STYLES, "styles.xml" doc_rels.add_relationship REL_SETTINGS, "settings.xml" doc_rels.add_relationship REL_FONT_TABLE, "fontTable.xml" add_part "word/_rels/document.xml.rels", doc_rels add_part "word/_rels/fontTable.xml.rels", font_rels add_part "word/document.xml", document add_part "word/settings.xml", settings add_part "word/styles.xml", styles add_part "word/fontTable.xml", fonts end |
Instance Attribute Details
#doc_rels ⇒ Object (readonly)
Returns the value of attribute doc_rels.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def doc_rels @doc_rels end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def document @document end |
#font_rels ⇒ Object (readonly)
Returns the value of attribute font_rels.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def font_rels @font_rels end |
#fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def fonts @fonts end |
#footers ⇒ Object (readonly)
Returns the value of attribute footers.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def @footers end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def headers @headers end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def settings @settings end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
6 7 8 |
# File 'lib/openxml/docx/package.rb', line 6 def styles @styles end |
Instance Method Details
#add_footer(footer) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/openxml/docx/package.rb', line 75 def () << = "footer#{.count}.xml" Package.content_types { override "/word/#{}", TYPE_FOOTER } add_part "word/#{}", relationship = doc_rels.add_relationship REL_FOOTER, relationship.id end |
#add_header(header) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/openxml/docx/package.rb', line 66 def add_header(header) headers << header header_name = "header#{headers.count}.xml" Package.content_types { override "/word/#{header_name}", TYPE_HEADER } add_part "word/#{header_name}", header relationship = doc_rels.add_relationship REL_HEADER, header_name relationship.id end |
#embed_truetype_font(path: nil, name: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/openxml/docx/package.rb', line 48 def (path: nil, name: nil) File.open(path, "rb") do |source_font| obfuscation_data = obfuscate_font source_font data = obfuscation_data[:bytes] << source_font.read destination_font_name = "font#{fonts.fonts.count + 1}.odttf" add_part "word/fonts/#{destination_font_name}", OpenXml::Parts::UnparsedPart.new(data) font_relationship = font_rels.add_relationship REL_FONT, "fonts/#{destination_font_name}" font_description = OpenXml::Docx::Elements::Font.new font_description.font_name = name = OpenXml::Docx::Elements::EmbedRegular.new .font_key = "{#{obfuscation_data[:key]}}" .relationship_id = font_relationship.id font_description << fonts << font_description end end |