# encoding: UTF-8 <-- magic comment, need this because of sime fancy fonts in the default scheme below. See http://stackoverflow.com/questions/6444826/ruby-utf-8-file-encoding require 'rubyXL/objects/ooxml_object' require 'rubyXL/objects/extensions' module RubyXL # http://www.schemacentral.com/sc/ooxml/e-a_ext-1.html class AExtension < OOXMLObject define_attribute(:uri, :string) define_element_name 'a:ext' attr_accessor :raw_xml def self.parse(node) obj = new obj.raw_xml = node.to_xml obj end def write_xml(xml, node_name_override = nil) self.raw_xml end end class AExtensionStorageArea < OOXMLObject #FIXME# define_child_node(RubyXL::AExtension, :collection => true) define_element_name 'a:extLst' end # http://www.schemacentral.com/sc/ooxml/e-a_srgbClr-1.html class RGBColorModelPercentage < OOXMLObject define_child_node(RubyXL::IntegerValue, :node_name => 'a:tint') define_child_node(RubyXL::IntegerValue, :node_name => 'a:shade') define_child_node(RubyXL::BooleanValue, :node_name => 'a:comp') define_child_node(RubyXL::BooleanValue, :node_name => 'a:inv') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gray') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alpha') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:sat') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lum') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:red') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:green') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueMod') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gamma') define_child_node(RubyXL::BooleanValue, :node_name => 'a:invGamma') define_attribute(:r, :int, :required => true) define_attribute(:g, :int, :required => true) define_attribute(:b, :int, :required => true) define_element_name 'a:scrgbClr' end # http://www.schemacentral.com/sc/ooxml/e-a_srgbClr-1.html class RGBColorModelHex < OOXMLObject define_child_node(RubyXL::IntegerValue, :node_name => 'a:tint') define_child_node(RubyXL::IntegerValue, :node_name => 'a:shade') define_child_node(RubyXL::BooleanValue, :node_name => 'a:comp') define_child_node(RubyXL::BooleanValue, :node_name => 'a:inv') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gray') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alpha') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:sat') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lum') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:red') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:green') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueMod') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gamma') define_child_node(RubyXL::BooleanValue, :node_name => 'a:invGamma') define_attribute(:val, :string, :required => true) define_element_name 'a:srgbClr' end # http://www.schemacentral.com/sc/ooxml/e-a_hslClr-1.html class HSLColor < OOXMLObject define_child_node(RubyXL::IntegerValue, :node_name => 'a:tint') define_child_node(RubyXL::IntegerValue, :node_name => 'a:shade') define_child_node(RubyXL::BooleanValue, :node_name => 'a:comp') define_child_node(RubyXL::BooleanValue, :node_name => 'a:inv') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gray') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alpha') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:sat') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lum') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:red') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:green') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueMod') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gamma') define_child_node(RubyXL::BooleanValue, :node_name => 'a:invGamma') define_attribute(:hue, :int, :required => true) define_attribute(:sat, :int, :required => true) define_attribute(:lum, :int, :required => true) define_element_name 'a:hslClr' end # http://www.schemacentral.com/sc/ooxml/e-a_sysClr-1.html class SystemColor < OOXMLObject define_child_node(RubyXL::IntegerValue, :node_name => 'a:tint') define_child_node(RubyXL::IntegerValue, :node_name => 'a:shade') define_child_node(RubyXL::BooleanValue, :node_name => 'a:comp') define_child_node(RubyXL::BooleanValue, :node_name => 'a:inv') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gray') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alpha') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:sat') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lum') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:red') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:green') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueMod') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gamma') define_child_node(RubyXL::BooleanValue, :node_name => 'a:invGamma') define_attribute(:val, RubyXL::ST_SystemColorVal, :required => true) define_attribute(:lastClr, :string) define_element_name 'a:sysClr' end # http://www.schemacentral.com/sc/ooxml/e-a_schemeClr-1.html class SchemeColor < OOXMLObject define_child_node(RubyXL::IntegerValue, :node_name => 'a:tint') define_child_node(RubyXL::IntegerValue, :node_name => 'a:shade') define_child_node(RubyXL::BooleanValue, :node_name => 'a:comp') define_child_node(RubyXL::BooleanValue, :node_name => 'a:inv') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gray') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alpha') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:sat') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lum') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:red') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:green') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueMod') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gamma') define_child_node(RubyXL::BooleanValue, :node_name => 'a:invGamma') define_attribute(:val, RubyXL::ST_SchemeColorVal, :required => true) define_element_name 'a:schemeClr' end # http://www.schemacentral.com/sc/ooxml/e-a_prstClr-1.html class PresetColor < OOXMLObject define_child_node(RubyXL::IntegerValue, :node_name => 'a:tint') define_child_node(RubyXL::IntegerValue, :node_name => 'a:shade') define_child_node(RubyXL::BooleanValue, :node_name => 'a:comp') define_child_node(RubyXL::BooleanValue, :node_name => 'a:inv') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gray') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alpha') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:alphaMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:hueMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:sat') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:satMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lum') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:lumMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:red') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:redMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:green') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:greenMod') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blue') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueOff') define_child_node(RubyXL::IntegerValue, :node_name => 'a:blueMod') define_child_node(RubyXL::BooleanValue, :node_name => 'a:gamma') define_child_node(RubyXL::BooleanValue, :node_name => 'a:invGamma') define_attribute(:val, RubyXL::ST_PresetColorVal, :required => true) define_element_name 'a:prstClr' end # http://www.schemacentral.com/sc/ooxml/t-a_CT_Color.html class CT_Color < OOXMLObject define_child_node(RubyXL::RGBColorModelPercentage) define_child_node(RubyXL::RGBColorModelHex) define_child_node(RubyXL::HSLColor) define_child_node(RubyXL::SystemColor) define_child_node(RubyXL::SchemeColor) define_child_node(RubyXL::PresetColor) end # http://www.schemacentral.com/sc/ooxml/e-a_clrScheme-1.html class ColorScheme < OOXMLObject define_child_node(RubyXL::CT_Color, :node_name => 'a:dk1') define_child_node(RubyXL::CT_Color, :node_name => 'a:lt1') define_child_node(RubyXL::CT_Color, :node_name => 'a:dk2') define_child_node(RubyXL::CT_Color, :node_name => 'a:lt2') define_child_node(RubyXL::CT_Color, :node_name => 'a:accent1') define_child_node(RubyXL::CT_Color, :node_name => 'a:accent2') define_child_node(RubyXL::CT_Color, :node_name => 'a:accent3') define_child_node(RubyXL::CT_Color, :node_name => 'a:accent4') define_child_node(RubyXL::CT_Color, :node_name => 'a:accent5') define_child_node(RubyXL::CT_Color, :node_name => 'a:accent6') define_child_node(RubyXL::CT_Color, :node_name => 'a:hlink') define_child_node(RubyXL::CT_Color, :node_name => 'a:folHlink') define_attribute(:name, :string, :required => true) define_element_name 'a:clrScheme' end class FontScheme < OOXMLObject #FIXME# define_element_name 'a:fontScheme' end class FormatScheme < OOXMLObject #FIXME# define_element_name 'a:fmtScheme' end # http://www.schemacentral.com/sc/ooxml/e-a_themeElements-1.html class ThemeElements < OOXMLObject define_child_node(RubyXL::ColorScheme) define_child_node(RubyXL::FontScheme) define_child_node(RubyXL::FormatScheme) define_child_node(RubyXL::AExtensionStorageArea) define_element_name 'a:themeElements' end # http://www.schemacentral.com/sc/ooxml/e-a_off-1.html class Offset < OOXMLObject define_attribute(:x, :int, :required => true) define_attribute(:y, :int, :required => true) define_element_name 'a:off' end # http://www.schemacentral.com/sc/ooxml/e-a_ext-2.html class Extents < OOXMLObject define_attribute(:cx, :int, :required => true) define_attribute(:cy, :int, :required => true) define_element_name 'a:ext' end # http://www.schemacentral.com/sc/ooxml/e-a_xfrm-4.html class TwoDTransform < OOXMLObject define_attribute(:rot, :int, :default => 0) define_attribute(:flipH, :bool, :default => false) define_attribute(:flipV, :bool, :default => false) define_child_node(RubyXL::Offset) define_child_node(RubyXL::Extents) define_element_name 'a:xfrm' end # http://www.schemacentral.com/sc/ooxml/e-a_gd-1.html class ShapeGuide < OOXMLObject define_attribute(:name, :string, :required => true) define_attribute(:fmla, :string, :required => true) define_element_name 'a:gd' end # http://www.schemacentral.com/sc/ooxml/e-a_avLst-1.html class AdjustValueList < OOXMLContainerObject define_child_node(RubyXL::ShapeGuide, :collection => true) define_element_name 'a:avLst' end # http://www.schemacentral.com/sc/ooxml/e-a_rect-1.html class ShapeTextRectangle < OOXMLObject define_attribute(:l, :int, :required => true) define_attribute(:t, :int, :required => true) define_attribute(:r, :int, :required => true) define_attribute(:b, :int, :required => true) define_element_name 'a:rect' end # http://www.schemacentral.com/sc/ooxml/e-a_custGeom-1.html class CustomGeometry < OOXMLObject define_child_node(RubyXL::AdjustValueList) define_child_node(RubyXL::AdjustValueList, :node_name => 'a:gdLst') # a:ahLst [0..1] List of Shape Adjust Handles # a:cxnLst [0..1] List of Shape Connection Sites define_child_node(RubyXL::ShapeTextRectangle) # a:pathLst [1..1] List of Shape Paths define_element_name 'a:custGeom' end # http://www.schemacentral.com/sc/ooxml/e-a_prstGeom-1.html class PresetGeometry < OOXMLObject define_child_node(RubyXL::AdjustValueList) define_attribute(:prst, RubyXL::ST_ShapeType, :required => true) define_element_name 'a:prstGeom' end # http://www.schemacentral.com/sc/ooxml/e-a_spPr-1.html class VisualProperties < OOXMLObject define_child_node(RubyXL::TwoDTransform) define_child_node(RubyXL::CustomGeometry) define_child_node(RubyXL::PresetGeometry) # a:noFill No Fill # a:solidFill Solid Fill # a:gradFill Gradient Fill # a:blipFill Picture Fill # a:pattFill Pattern Fill # a:grpFill Group Fill # a:ln [0..1] # a:effectLst Effect Container # a:effectDag Effect Container # a:scene3d [0..1] 3-D Scene # a:sp3d [0..1] 3-D Shape Properties # a:extLst [0..1] Extension List define_attribute(:bwMode, RubyXL::ST_BlackWhiteMode) define_child_node(RubyXL::AExtensionStorageArea) define_element_name 'a:spPr' end # http://www.schemacentral.com/sc/ooxml/e-a_spDef-1.html class ShapeDefault < OOXMLObject define_child_node(RubyXL::VisualProperties) # a:bodyPr [1..1] BodyProperties # a:lstStyle [1..1] TextListStyles # a:style [0..1] Shape Style define_child_node(RubyXL::AExtensionStorageArea) define_element_name 'a:spDef' end # http://www.schemacentral.com/sc/ooxml/e-a_objectDefaults-1.html class ObjectDefaults < OOXMLObject define_child_node(RubyXL::ShapeDefault) # a:spDef [0..1] # a:lnDef [0..1] LineDefault # a:txDef [0..1] TextDefault define_child_node(RubyXL::AExtensionStorageArea) define_element_name 'a:objectDefaults' end # http://www.schemacentral.com/sc/ooxml/e-a_extraClrScheme-1.html class ExtraColorScheme < OOXMLObject # a:clrScheme [1..1] ColorScheme # a:clrMap [0..1] ColorMap define_element_name 'a:extraClrScheme' end # http://www.schemacentral.com/sc/ooxml/e-a_extraClrSchemeLst-1.html class ExtraColorSchemeList < OOXMLContainerObject define_child_node(RubyXL::ExtraColorScheme, :collection => true) define_element_name 'a:extraClrSchemeLst' end # http://www.schemacentral.com/sc/ooxml/e-a_custClr-1.html class CustomColor < OOXMLObject # a:scrgbClr RGB Color Model - Percentage Variant # a:srgbClr RGB Color Model - Hex Variant # a:hslClr Hue, Saturation, Luminance Color Model # a:sysClr System Color # a:schemeClr Scheme Color # a:prstClr Preset Color define_attribute(:name, :string, :default => '') define_element_name 'a:custClr' end # http://www.schemacentral.com/sc/ooxml/e-a_custClrLst-1.html class CustomColorList < OOXMLContainerObject define_child_node(RubyXL::CustomColor, :collection => true) define_element_name 'a:custClrLst' end # http://www.schemacentral.com/sc/ooxml/e-a_theme.html class Theme < OOXMLTopLevelObject define_attribute(:name, :string, :default => '') define_child_node(RubyXL::ThemeElements) define_child_node(RubyXL::ObjectDefaults) define_child_node(RubyXL::ExtraColorSchemeList) define_child_node(RubyXL::CustomColorList) define_child_node(RubyXL::AExtensionStorageArea) define_element_name 'a:theme' set_namespaces('xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main') def self.xlsx_path File.join('xl', 'theme', 'theme1.xml') end def self.content_type 'application/vnd.openxmlformats-officedocument.theme+xml' end ###### Temporary storage of the theme until I'm done with fully implementing ###### all of its intricacies attr_accessor :raw_xml def self.parse_file(dirpath) full_path = File.join(dirpath, xlsx_path) return nil unless File.exist?(full_path) # test = super # puts test.inspect obj = self.new obj.raw_xml = File.open(full_path, 'r').read obj end def write_xml raw_xml || # Use fallback theme. ' ' end ###### end end