Class: Uniword::Builder::WatermarkBuilder
- Inherits:
-
Object
- Object
- Uniword::Builder::WatermarkBuilder
- Defined in:
- lib/uniword/builder/watermark_builder.rb
Overview
Builds watermark elements for documents.
Watermarks in OOXML are implemented as VML shapes placed in the header. The shape uses a textpath for the watermark text with semi-transparent fill.
Class Method Summary collapse
-
.build_paragraph(text, font: "Calibri", size: 60, color: nil, opacity: "0.3", angle: -45)) ⇒ Wordprocessingml::Paragraph
Build a watermark paragraph containing the VML shape.
-
.build_shape(text, font: "Calibri", size: 60, color: nil, opacity: "0.3", angle: -45)) ⇒ Vml::Shape
Build a watermark VML shape.
Class Method Details
.build_paragraph(text, font: "Calibri", size: 60, color: nil, opacity: "0.3", angle: -45)) ⇒ Wordprocessingml::Paragraph
Build a watermark paragraph containing the VML shape
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/uniword/builder/watermark_builder.rb', line 64 def self.build_paragraph(text, font: "Calibri", size: 60, color: nil, opacity: "0.3", angle: -45) para = Wordprocessingml::Paragraph.new run = Wordprocessingml::Run.new run.pictures << Wordprocessingml::Picture.new( shape: build_shape(text, font: font, size: size, color: color, opacity: opacity, angle: angle), ) para.runs << run para end |
.build_shape(text, font: "Calibri", size: 60, color: nil, opacity: "0.3", angle: -45)) ⇒ Vml::Shape
Build a watermark VML shape
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/uniword/builder/watermark_builder.rb', line 29 def self.build_shape(text, font: "Calibri", size: 60, color: nil, opacity: "0.3", angle: -45) fill_color = color || "D0D0D0" shape = Vml::Shape.new( id: "PowerPlusWaterMarkObject1", type: "#_x0000_t136", style: watermark_style(angle), fillcolor: fill_color, strokecolor: "none", ) shape.fill = Vml::Fill.new( type: "tile", opacity: opacity, color: fill_color, ) shape.textpath = Vml::TextPath.new( string: text, style: "font-family:'#{font}';font-size:#{size}pt", ) shape end |