ooxml_parser 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. checksums.yaml +7 -0
  2. data/.overcommit.yml +35 -0
  3. data/Changelog.md +25 -0
  4. data/LICENSE.txt +661 -0
  5. data/README.md +26 -0
  6. data/circle.yml +3 -0
  7. data/lib/ooxml_parser/common_parser/common_data/alingment.rb +56 -0
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content.rb +34 -0
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +123 -0
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis.rb +34 -0
  11. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis_title.rb +38 -0
  12. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_cells_range.rb +23 -0
  13. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_legend.rb +33 -0
  14. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_point.rb +11 -0
  15. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_style/office_2007_chart_style.rb +17 -0
  16. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_style/office_2010_chart_style.rb +17 -0
  17. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/display_labels_properties.rb +26 -0
  18. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +49 -0
  19. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +23 -0
  20. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_position.rb +35 -0
  21. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +11 -0
  22. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_wrap_drawing.rb +39 -0
  23. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +32 -0
  24. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/docx_graphic.rb +34 -0
  25. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/group/docx_group_element.rb +10 -0
  26. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/group/docx_grouped_drawing.rb +34 -0
  27. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +27 -0
  28. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +26 -0
  29. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb +25 -0
  30. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties/preset_text_warp.rb +16 -0
  31. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties.rb +30 -0
  32. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +37 -0
  33. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_pattern_fill.rb +20 -0
  34. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/gradient_color/docx_gradient_color.rb +30 -0
  35. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/gradient_color/docx_single_gradient_color.rb +6 -0
  36. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/solid_color/docx_solid_color.rb +10 -0
  37. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_element.rb +10 -0
  38. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path.rb +44 -0
  39. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/ooxml_custom_geometry.rb +23 -0
  40. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb +43 -0
  41. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +54 -0
  42. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/text_box.rb +25 -0
  43. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +40 -0
  44. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +31 -0
  45. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/line/line_end/line_size.rb +20 -0
  46. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/line/line_end.rb +21 -0
  47. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_style/docx_shape_style.rb +5 -0
  48. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb +31 -0
  49. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group_element.rb +10 -0
  50. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group_properties.rb +6 -0
  51. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +26 -0
  52. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb +24 -0
  53. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_fill.rb +26 -0
  54. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +24 -0
  55. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/common_non_visual_properties.rb +25 -0
  56. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/non_visual_properties.rb +19 -0
  57. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/non_visual_shape_properties.rb +20 -0
  58. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape.rb +28 -0
  59. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_placeholder.rb +18 -0
  60. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_properties/ooxml_shift.rb +15 -0
  61. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_properties/transform_effect.rb +28 -0
  62. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_properties.rb +13 -0
  63. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/text_body/ooxml_text_box.rb +26 -0
  64. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/text_body/text_body.rb +23 -0
  65. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +58 -0
  66. data/lib/ooxml_parser/common_parser/common_data/color.rb +473 -0
  67. data/lib/ooxml_parser/common_parser/common_data/colors/color_alpha_channel.rb +14 -0
  68. data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +21 -0
  69. data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +150 -0
  70. data/lib/ooxml_parser/common_parser/common_data/colors/image/fill_rectangle.rb +22 -0
  71. data/lib/ooxml_parser/common_parser/common_data/colors/image/stretching.rb +11 -0
  72. data/lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb +32 -0
  73. data/lib/ooxml_parser/common_parser/common_data/colors/image_properties.rb +16 -0
  74. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/gradient_stop.rb +15 -0
  75. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/linear_gradient.rb +10 -0
  76. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb +35 -0
  77. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/presentation_pattern.rb +22 -0
  78. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill.rb +33 -0
  79. data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +14 -0
  80. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +22 -0
  81. data/lib/ooxml_parser/common_parser/common_data/colors/tile.rb +21 -0
  82. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +127 -0
  83. data/lib/ooxml_parser/common_parser/common_data/font_style.rb +101 -0
  84. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +53 -0
  85. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +87 -0
  86. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +48 -0
  87. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/outline.rb +23 -0
  88. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/strikeout.rb +16 -0
  89. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +79 -0
  90. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +24 -0
  91. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering/numbering_properties/numbering_level.rb +25 -0
  92. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering/numbering_properties.rb +69 -0
  93. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering.rb +18 -0
  94. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +115 -0
  95. data/lib/ooxml_parser/common_parser/common_data/paragraph.rb +35 -0
  96. data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +35 -0
  97. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +47 -0
  98. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_cell_margin.rb +20 -0
  99. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_element.rb +20 -0
  100. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_look.rb +43 -0
  101. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +49 -0
  102. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +83 -0
  103. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_elements.rb +21 -0
  104. data/lib/ooxml_parser/common_parser/common_data/table/properties/whole_table/line_join.rb +19 -0
  105. data/lib/ooxml_parser/common_parser/common_data/table/properties/whole_table/table_cell_style.rb +20 -0
  106. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb +43 -0
  107. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +142 -0
  108. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/merge.rb +18 -0
  109. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/border.rb +25 -0
  110. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +125 -0
  111. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/table_cell_line.rb +35 -0
  112. data/lib/ooxml_parser/common_parser/common_data/table/row/row/table_row_properties.rb +22 -0
  113. data/lib/ooxml_parser/common_parser/common_data/table/row/row.rb +33 -0
  114. data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +9 -0
  115. data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +77 -0
  116. data/lib/ooxml_parser/common_parser/common_data/table.rb +41 -0
  117. data/lib/ooxml_parser/common_parser/common_data/underline.rb +40 -0
  118. data/lib/ooxml_parser/common_parser/common_document_structure.rb +7 -0
  119. data/lib/ooxml_parser/configuration.rb +20 -0
  120. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comment.rb +28 -0
  121. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +10 -0
  122. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_properties.rb +21 -0
  123. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +70 -0
  124. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/accent.rb +11 -0
  125. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/bar.rb +10 -0
  126. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/box.rb +11 -0
  127. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/delimeter.rb +12 -0
  128. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/fraction.rb +11 -0
  129. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/function.rb +11 -0
  130. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/group_char.rb +13 -0
  131. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/index.rb +12 -0
  132. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/limit.rb +12 -0
  133. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix/matrix_row.rb +10 -0
  134. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb +10 -0
  135. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/operator.rb +13 -0
  136. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/radical.rb +11 -0
  137. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula.rb +203 -0
  138. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/offset.rb +10 -0
  139. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shadow.rb +10 -0
  140. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties/shape_margins.rb +11 -0
  141. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties/shape_size.rb +10 -0
  142. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties/stroke.rb +10 -0
  143. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties.rb +16 -0
  144. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +40 -0
  145. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/text_fill.rb +13 -0
  146. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/text_outline.rb +22 -0
  147. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +388 -0
  148. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +46 -0
  149. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +87 -0
  150. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style/bookmark.rb +10 -0
  151. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style/paragraph_tab.rb +19 -0
  152. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style/style_parametres.rb +35 -0
  153. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb +56 -0
  154. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +324 -0
  155. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +37 -0
  156. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/image.rb +15 -0
  157. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns/column.rb +10 -0
  158. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +37 -0
  159. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/document_grid.rb +29 -0
  160. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +49 -0
  161. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_margins.rb +42 -0
  162. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +88 -0
  163. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb +84 -0
  164. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +232 -0
  165. data/lib/ooxml_parser/docx_parser/docx_parser.rb +16 -0
  166. data/lib/ooxml_parser/helpers/string_helper.rb +22 -0
  167. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_comment/presentation_comment_author.rb +25 -0
  168. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_comment.rb +31 -0
  169. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +40 -0
  170. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +44 -0
  171. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/background.rb +19 -0
  172. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb +34 -0
  173. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_alternate_content.rb +25 -0
  174. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/non_visual_shape_properties/hyperlinks/hyperlink_for_hover.rb +23 -0
  175. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/extents.rb +10 -0
  176. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/offset.rb +10 -0
  177. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/text_body/paragraph.rb +10 -0
  178. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/text_body/text_field.rb +18 -0
  179. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shapes_grouping/shapes_grouping.rb +9 -0
  180. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping/grouping_properties.rb +16 -0
  181. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping.rb +30 -0
  182. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/animation_effect/animation_effect.rb +22 -0
  183. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/behavior.rb +28 -0
  184. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/target_element.rb +31 -0
  185. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/set_time_node.rb +20 -0
  186. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing/condition.rb +26 -0
  187. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing.rb +33 -0
  188. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +52 -0
  189. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing.rb +23 -0
  190. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/sound_action/sound/sound.rb +18 -0
  191. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/sound_action/sound_action.rb +18 -0
  192. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +43 -0
  193. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition_properties/transition_properties.rb +9 -0
  194. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +110 -0
  195. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide_size.rb +20 -0
  196. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +62 -0
  197. data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +15 -0
  198. data/lib/ooxml_parser/version.rb +6 -0
  199. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment/excel_comment_character/excel_comment_character_properties.rb +27 -0
  200. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment/excel_comment_character.rb +25 -0
  201. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment.rb +20 -0
  202. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +43 -0
  203. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_format_properties.rb +21 -0
  204. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/pane.rb +23 -0
  205. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +18 -0
  206. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +24 -0
  207. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position/xlsx_drawing_position_parameters.rb +22 -0
  208. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position.rb +22 -0
  209. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_shape_grouping.rb +37 -0
  210. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb +49 -0
  211. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/alignment.rb +30 -0
  212. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb +25 -0
  213. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/ooxml_font.rb +38 -0
  214. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb +95 -0
  215. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb +47 -0
  216. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb +19 -0
  217. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_table.rb +30 -0
  218. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +74 -0
  219. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +108 -0
  220. data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +15 -0
  221. data/lib/ooxml_parser.rb +35 -0
  222. data/ooxml_parser.gemspec +30 -0
  223. metadata +310 -0
@@ -0,0 +1,473 @@
1
+ require_relative 'colors/color_alpha_channel'
2
+ require_relative 'colors/hsl_color'
3
+ require_relative 'colors/scheme_color'
4
+ require_relative 'colors/color_properties'
5
+ require_relative 'colors/theme_colors'
6
+ # @author Pavel.Lobashov
7
+ # Class for Color in RGB
8
+ module OoxmlParser
9
+ class Color
10
+ # @return [Array] Deprecated Indexed colors
11
+ # List of color duplicated from `OpenXML Sdk IndexedColors` class
12
+ # See https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx
13
+ COLOR_INDEXED =
14
+ %w(
15
+ 000000
16
+ FFFFFF
17
+ FF0000
18
+ 00FF00
19
+ 0000FF
20
+ FFFF00
21
+ FF00FF
22
+ 00FFFF
23
+ 000000
24
+ FFFFFF
25
+ FF0000
26
+ 00FF00
27
+ 0000FF
28
+ FFFF00
29
+ FF00FF
30
+ 00FFFF
31
+ 800000
32
+ 008000
33
+ 000080
34
+ 808000
35
+ 800080
36
+ 008080
37
+ C0C0C0
38
+ 808080
39
+ 9999FF
40
+ 993366
41
+ FFFFCC
42
+ CCFFFF
43
+ 660066
44
+ FF8080
45
+ 0066CC
46
+ CCCCFF
47
+ 000080
48
+ FF00FF
49
+ FFFF00
50
+ 00FFFF
51
+ 800080
52
+ 800000
53
+ 008080
54
+ 0000FF
55
+ 00CCFF
56
+ CCFFFF
57
+ CCFFCC
58
+ FFFF99
59
+ 99CCFF
60
+ FF99CC
61
+ CC99FF
62
+ FFCC99
63
+ 3366FF
64
+ 33CCCC
65
+ 99CC00
66
+ FFCC00
67
+ FF9900
68
+ FF6600
69
+ 666699
70
+ 969696
71
+ 003366
72
+ 339966
73
+ 003300
74
+ 333300
75
+ 993300
76
+ 993366
77
+ 333399
78
+ 333333
79
+ n/a
80
+ n/a
81
+ ).freeze
82
+
83
+ # @return [Integer] Value of Red Part
84
+ attr_accessor :red
85
+ # @return [Integer] Value of Green Part
86
+ attr_accessor :green
87
+ # @return [Integer] Value of Blue Part
88
+ attr_accessor :blue
89
+ # @return [String] Value of Color Style
90
+ attr_accessor :style
91
+ alias set_style style=
92
+
93
+ # @return [Integer] Value of alpha-channel
94
+ attr_accessor :alpha_channel
95
+ alias set_alpha_channel alpha_channel=
96
+
97
+ attr_accessor :position
98
+ attr_accessor :properties
99
+
100
+ # Value of color if non selected
101
+ VALUE_FOR_NONE_COLOR = nil
102
+
103
+ def initialize(new_red = VALUE_FOR_NONE_COLOR, new_green = VALUE_FOR_NONE_COLOR, new_blue = VALUE_FOR_NONE_COLOR)
104
+ @red = new_red
105
+ @green = new_green
106
+ @blue = new_blue
107
+ end
108
+
109
+ def to_s
110
+ if @red == VALUE_FOR_NONE_COLOR && @green == VALUE_FOR_NONE_COLOR && @blue == VALUE_FOR_NONE_COLOR
111
+ 'none'
112
+ else
113
+ "RGB (#{@red}, #{@green}, #{@blue})"
114
+ end
115
+ end
116
+
117
+ def to_hex
118
+ (@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
119
+ end
120
+
121
+ alias to_int16 to_hex
122
+
123
+ def none?
124
+ (@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR)
125
+ end
126
+
127
+ def white?
128
+ (@red == 255) && (@green == 255) && (@blue == 255)
129
+ end
130
+
131
+ def copy
132
+ Color.new(@red, @green, @blue)
133
+ end
134
+
135
+ def ==(other)
136
+ if other.is_a?(Color)
137
+ if nil?
138
+ false
139
+ elsif (@red == other.red) && (@green == other.green) && (@blue == other.blue)
140
+ true
141
+ elsif (none? && other.white?) || (white? && other.none?)
142
+ true
143
+ else
144
+ false
145
+ end
146
+ else
147
+ false
148
+ end
149
+ end
150
+
151
+ # To compare color, which look alike
152
+ # @param [String or Color] color_to_check color to compare
153
+ # @param [Integer] delta max delta for each of specters
154
+ def looks_like?(color_to_check = nil, delta = 8)
155
+ color_to_check = color_to_check.converted_color if color_to_check.is_a?(SchemeColor)
156
+ color_to_check = color_to_check.color if color_to_check.is_a?(ForegroundColor)
157
+ color_to_check = color_to_check.color.converted_color if color_to_check.is_a?(PresentationFill)
158
+ color_to_check = Color.parse(color_to_check) if color_to_check.is_a?(String)
159
+ color_to_check = Color.parse(color_to_check.to_s) if color_to_check.is_a?(Symbol)
160
+ color_to_check = Color.parse(color_to_check.value) if color_to_check.is_a?(DocxColor)
161
+ return false if none? && !color_to_check.none?
162
+ return false if !none? && color_to_check.none?
163
+ return true if self == color_to_check
164
+ red = color_to_check.red
165
+ green = color_to_check.green
166
+ blue = color_to_check.blue
167
+ ((self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta) ? true : false
168
+ end
169
+
170
+ def calculate_with_tint!(tint)
171
+ @red += (tint.to_f * (255 - @red)).to_i
172
+ @green += (tint.to_f * (255 - @green)).to_i
173
+ @blue += (tint.to_f * (255 - @blue)).to_i
174
+ end
175
+
176
+ def calculate_with_shade!(shade)
177
+ @red = (@red * shade.to_f).to_i
178
+ @green = (@green * shade.to_f).to_i
179
+ @blue = (@blue * shade.to_f).to_i
180
+ end
181
+
182
+ def shade(shade_value)
183
+ red = Color.scrgb_to_srgb(Color.shade_for_component(Color.srgb_to_scrgb(@red), shade_value))
184
+ green = Color.scrgb_to_srgb(Color.shade_for_component(Color.srgb_to_scrgb(@green), shade_value))
185
+ blue = Color.scrgb_to_srgb(Color.shade_for_component(Color.srgb_to_scrgb(@blue), shade_value))
186
+ Color.new(red, green, blue)
187
+ end
188
+
189
+ def tint(shade_value)
190
+ red = Color.scrgb_to_srgb(Color.tint_for_component(Color.srgb_to_scrgb(@red), shade_value))
191
+ green = Color.scrgb_to_srgb(Color.tint_for_component(Color.srgb_to_scrgb(@green), shade_value))
192
+ blue = Color.scrgb_to_srgb(Color.tint_for_component(Color.srgb_to_scrgb(@blue), shade_value))
193
+ Color.new(red, green, blue)
194
+ end
195
+
196
+ # code from js to ruby
197
+ # https://github.com/ONLYOFFICE/ONLYOFFICE-OnlineEditors/blob/master/OfficeWeb/sdk/Excel/model/DrawingObjects/Format/Format.js
198
+ def to_hsl
199
+ max_hls = 255.0
200
+ cd13 = 1.0 / 3.0
201
+ cd23 = 2.0 / 3.0
202
+ hls_color = HSLColor.new
203
+ min = [@red, @green, @blue].min.to_f
204
+ max = [@red, @green, @blue].max.to_f
205
+ delta = (max - min).to_f
206
+ dmax = (max + min) / 255.0
207
+ ddelta = delta / 255.0
208
+ hls_color.l = dmax / 2.0
209
+
210
+ if delta != 0
211
+ hls_color.s = if hls_color.l < 0.5
212
+ ddelta / dmax
213
+ else
214
+ ddelta / (2.0 - dmax)
215
+ end
216
+ ddelta *= 1_530.0
217
+ d_r = (max - @red) / ddelta
218
+ d_g = (max - @green) / ddelta
219
+ d_b = (max - @blue) / ddelta
220
+
221
+ if @red == max
222
+ hls_color.h = d_b - d_r
223
+ elsif @green == max
224
+ hls_color.h = cd13 + d_r - d_b
225
+ elsif @blue == max
226
+ hls_color.h = cd23 + d_g - d_r
227
+ end
228
+
229
+ hls_color.h += 1 if hls_color.h < 0
230
+ hls_color.h -= 1 if hls_color.h < 1
231
+ end
232
+ hls_color.h = ((hls_color.h * max_hls).round >> 0) & 0xFF
233
+ hls_color.h = 0 if hls_color.h < 0
234
+ hls_color.h = 255 if hls_color.h > 255
235
+
236
+ hls_color.l = ((hls_color.l * max_hls).round >> 0) & 0xFF
237
+ hls_color.l = 0 if hls_color.l < 0
238
+ hls_color.l = 255 if hls_color.l > 255
239
+
240
+ hls_color.s = ((hls_color.s * max_hls).round >> 0) & 0xFF
241
+ hls_color.s = 0 if hls_color.s < 0
242
+ hls_color.s = 255 if hls_color.s > 255
243
+
244
+ hls_color
245
+ end
246
+
247
+ # redefine code from our to_hsl realisation to standartised way for services like http://serennu.com/colour/hsltorgb.php
248
+ def to_hsl_standardised
249
+ hsl = to_hsl
250
+ hsl.h = hsl.h * 360 / 256
251
+ hsl.l = (hsl.l * 100.0 / 255.0).round
252
+ hsl.s = (hsl.s * 100.0 / 255.0).round
253
+ hsl
254
+ end
255
+
256
+ class << self
257
+ def generate_random_color
258
+ Color.new(rand(256), rand(256), rand(256))
259
+ end
260
+
261
+ alias random generate_random_color
262
+
263
+ def from_int16(color)
264
+ return nil unless color
265
+ return Color.new(nil, nil, nil) if color == 'auto' || color == 'null'
266
+
267
+ char_array = color.split(//)
268
+ alpha_channel, red, green, blue = nil
269
+ if char_array.length == 6
270
+ red = (char_array[0] + char_array[1]).hex
271
+ green = (char_array[2] + char_array[3]).hex
272
+ blue = (char_array[4] + char_array[5]).hex
273
+ elsif char_array.length == 8
274
+ alpha_channel = (char_array[0] + char_array[1]).hex
275
+ red = (char_array[2] + char_array[3]).hex
276
+ green = (char_array[4] + char_array[5]).hex
277
+ blue = (char_array[6] + char_array[7]).hex
278
+ end
279
+ font_color = Color.new(red, green, blue)
280
+ font_color.set_alpha_channel(alpha_channel) if alpha_channel
281
+ font_color
282
+ end
283
+
284
+ def parse_color_hash(hash)
285
+ Color.new(hash['red'], hash['green'], hash['blue'])
286
+ end
287
+
288
+ # Read array of color from the AllTestData's constant
289
+ # @param [Array] const_array_name - array of the string
290
+ # @return [Array, Color] array of color
291
+ def array_from_const(const_array_name)
292
+ const_array_name.map { |current_color| Color.parse_string(current_color) }
293
+ end
294
+
295
+ def get_rgb_by_color_index(index)
296
+ color_by_index = COLOR_INDEXED[index]
297
+ color_by_index == 'n/a' ? Color.new : Color.from_int16(color_by_index)
298
+ end
299
+
300
+ def parse_string(str)
301
+ return str if str.is_a?(Color)
302
+ return Color.new(VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR) if str == 'none' || str == '' || str == 'transparent' || str.nil?
303
+ split = if str.include?('RGB (') || str.include?('rgb(')
304
+ str.gsub(/[(RGBrgb\(\) )]/, '').split(',')
305
+ elsif str.include?('RGB ') || str.include?('rgb')
306
+ str.gsub(/RGB |rgb/, '').split(', ')
307
+ else
308
+ raise "Incorrect data for color to parse: '#{str}'"
309
+ end
310
+
311
+ Color.new(split[0].to_i, split[1].to_i, split[2].to_i)
312
+ end
313
+
314
+ alias parse parse_string
315
+
316
+ def parse_int16_string(color)
317
+ return nil if color.nil?
318
+
319
+ char_array = color.split(//)
320
+ red = (char_array[0] + char_array[1]).hex
321
+ green = (char_array[2] + char_array[3]).hex
322
+ blue = (char_array[4] + char_array[5]).hex
323
+ Color.new(red, green, blue)
324
+ end
325
+
326
+ def srgb_to_scrgb(color)
327
+ lineal_value = color.to_f / 255.0
328
+ result_color = if lineal_value < 0
329
+ 0
330
+ elsif lineal_value <= 0.04045
331
+ lineal_value / 12.92
332
+ elsif lineal_value <= 1
333
+ ((lineal_value + 0.055) / 1.055)**2.4
334
+ else
335
+ 1
336
+ end
337
+ result_color
338
+ end
339
+
340
+ def scrgb_to_srgb(color)
341
+ result_color = if color < 0
342
+ 0
343
+ elsif color <= 0.0031308
344
+ color * 12.92
345
+ elsif color < 1
346
+ 1.055 * (color**(1.0 / 2.4)) - 0.055
347
+ else
348
+ 1
349
+ end
350
+ (result_color * 255.0).to_i
351
+ end
352
+
353
+ def shade_for_component(color_component, shade_value)
354
+ if color_component * shade_value < 0
355
+ 0
356
+ elsif color_component * shade_value > 1
357
+ 1
358
+ else
359
+ color_component * shade_value
360
+ end
361
+ end
362
+
363
+ def tint_for_component(color_component, tint)
364
+ if tint > 0
365
+ color_component * (1 - tint) + tint
366
+ else
367
+ color_component * (1 + tint)
368
+ end
369
+ end
370
+
371
+ def to_color(something)
372
+ case something
373
+ when SchemeColor
374
+ something.converted_color
375
+ when ForegroundColor, DocxColorScheme
376
+ something.color
377
+ when PresentationFill
378
+ if something.color.respond_to? :converted_color
379
+ something.color.converted_color
380
+ else
381
+ something.color
382
+ end
383
+ when String
384
+ Color.parse(something)
385
+ when Symbol
386
+ Color.parse(something.to_s)
387
+ when DocxColor
388
+ Color.parse(something.value)
389
+ else
390
+ something
391
+ end
392
+ end
393
+
394
+ def parse_color_tag(color_tag)
395
+ unless color_tag.nil?
396
+ if color_tag.attribute('indexed').nil? && !color_tag.attribute('rgb').nil?
397
+ if color_tag.attribute('rgb').value.is_a?(String)
398
+ return Color.from_int16(color_tag.attribute('rgb').value.to_s)
399
+ end
400
+ return Color.from_int16(color_tag.attribute('rgb').value.value.to_s)
401
+ elsif color_tag.attribute('rgb').nil? && !color_tag.attribute('indexed').nil?
402
+ if color_tag.attribute('indexed').value.is_a?(String)
403
+ return Color.get_rgb_by_color_index(color_tag.attribute('indexed').value.to_i)
404
+ end
405
+ return Color.get_rgb_by_color_index(color_tag.attribute('indexed').value.value.to_i)
406
+ elsif !color_tag.attribute('theme').nil?
407
+ return ThemeColors.parse_color_theme(color_tag)
408
+ end
409
+ end
410
+ nil
411
+ end
412
+
413
+ def parse_scheme_color(scheme_color_node)
414
+ color = ThemeColors.list[scheme_color_node.attribute('val').value.to_sym]
415
+ hls = HSLColor.rgb_to_hsl(color)
416
+ scheme_color_node.xpath('*').each do |scheme_color_node_child|
417
+ case scheme_color_node_child.name
418
+ when 'lumMod'
419
+ hls.l = hls.l * (scheme_color_node_child.attribute('val').value.to_f / 100_000.0)
420
+ when 'lumOff'
421
+ hls.l = hls.l + (scheme_color_node_child.attribute('val').value.to_f / 100_000.0)
422
+ end
423
+ end
424
+ color = hls.to_rgb
425
+ color.alpha_channel = ColorAlphaChannel.parse(scheme_color_node)
426
+ color
427
+ end
428
+
429
+ def parse_color_model(color_model_parent_node)
430
+ color = nil
431
+ tint = nil
432
+ color_model_parent_node.xpath('*').each do |color_model_node|
433
+ color_model_node.xpath('*').each do |color_mode_node_child|
434
+ case color_mode_node_child.name
435
+ when 'tint'
436
+ tint = color_mode_node_child.attribute('val').value.to_f / 100_000.0
437
+ end
438
+ end
439
+ case color_model_node.name
440
+ when 'scrgbClr'
441
+ color = Color.new(color_model_node.attribute('r').value.to_i, color_model_node.attribute('g').value.to_i, color_model_node.attribute('b').value.to_i)
442
+ color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
443
+ when 'srgbClr'
444
+ color = Color.from_int16(color_model_node.attribute('val').value)
445
+ color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
446
+ when 'schemeClr'
447
+ color = parse_scheme_color(color_model_node)
448
+ end
449
+ end
450
+ return nil unless color
451
+ color.calculate_with_tint!(1.0 - tint) if tint
452
+ color
453
+ end
454
+
455
+ def parse_color(color_node)
456
+ case color_node.name
457
+ when 'srgbClr'
458
+ color = Color.from_int16(color_node.attribute('val').value)
459
+ color.properties = ColorProperties.parse(color_node)
460
+ color
461
+ when 'schemeClr'
462
+ color = SchemeColor.new
463
+ color.value = ThemeColors.list[color_node.attribute('val').value.to_sym]
464
+ color.properties = ColorProperties.parse(color_node)
465
+ color.converted_color = HSLColor.calculate_with_luminance color.value,
466
+ color.properties.luminance_modulation,
467
+ color.properties.luminance_offset
468
+ color
469
+ end
470
+ end
471
+ end
472
+ end
473
+ end
@@ -0,0 +1,14 @@
1
+ # Class for working with AlphaChannel
2
+ module OoxmlParser
3
+ class ColorAlphaChannel
4
+ # Parse AlphaChannel value
5
+ # @param node [Nokogiri::XML::Element] node to parse
6
+ # @return [Fixnum] value of AlphaChannel
7
+ def self.parse(node)
8
+ alpha_channel_node = node.xpath('a:alpha', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').first
9
+ alpha_channel_node = node.xpath('w14:alpha', 'xmlns:w14' => 'http://schemas.microsoft.com/office/word/2010/wordml').first if alpha_channel_node.nil?
10
+ return 100.0 if alpha_channel_node.nil?
11
+ (alpha_channel_node.attribute('val').value.to_f / 1_000.0).round(0)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # Class for color transformations
2
+ module OoxmlParser
3
+ class ColorProperties
4
+ attr_accessor :alpha, :luminance_modulation, :luminance_offset
5
+
6
+ def self.parse(color_properties_node)
7
+ properties = ColorProperties.new
8
+ color_properties_node.xpath('*').each do |color_properties_node_child|
9
+ case color_properties_node_child.name
10
+ when 'alpha'
11
+ properties.alpha = (color_properties_node_child.attribute('val').value.to_f / 1_000.0).round
12
+ when 'lumMod'
13
+ properties.luminance_modulation = color_properties_node_child.attribute('val').value.to_f / 100_000.0
14
+ when 'lumOff'
15
+ properties.luminance_offset = color_properties_node_child.attribute('val').value.to_f / 100_000.0
16
+ end
17
+ end
18
+ properties
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,150 @@
1
+ # HSL is one of the most common cylindrical-coordinate representations of points in an RGB color model.
2
+ # HSL stands for hue, saturation, and lightness, and is often also called HLS.
3
+ module OoxmlParser
4
+ class HSLColor
5
+ attr_accessor :a, :h, :s, :l
6
+
7
+ # Hue - The "attribute of a visual sensation according to which an area appears to be similar to one of
8
+ # the perceived colors: red, yellow, green, and blue, or to a combination of two of them".
9
+ # Saturation - The "colorfulness of a stimulus relative to its own brightness".
10
+ # Lightness - The "brightness relative to the brightness of a similarly illuminated white".
11
+ def initialize(hue = 0, saturation = 0, lightness = 0, a = nil)
12
+ @a = a
13
+ @h = hue
14
+ @s = saturation
15
+ @l = lightness
16
+ end
17
+
18
+ def self.rgb_to_hsl(rgb_color)
19
+ hls_color = HSLColor.new
20
+ red = rgb_color.red.to_f # / 255.0
21
+ green = rgb_color.green.to_f # / 255.0
22
+ blue = rgb_color.blue.to_f # / 255.0
23
+
24
+ min = [red, green, blue].min.to_f
25
+ max = [red, green, blue].max.to_f
26
+
27
+ delta = (max - min).to_f
28
+ hls_color.l = (min + max) / 255.0 / 2.0
29
+ hls_color.a = rgb_color.alpha_channel.to_f / 255.0
30
+
31
+ unless max == min
32
+ hls_color.s = delta / (255.0 - (255.0 - max - min).abs)
33
+
34
+ hls_color.h = case
35
+ when max == red && green >= blue
36
+ 60.0 * (green - blue) / delta
37
+ when max == red && green < blue
38
+ 60.0 * (green - blue) / delta + 360.0
39
+ when max == green
40
+ 60.0 * (blue - red) / delta + 120.0
41
+ else
42
+ 60.0 * (red - green) / delta + 240.0
43
+ end
44
+ end
45
+
46
+ hls_color
47
+ end
48
+
49
+ # Chroma - The "colorfulness relative to the brightness of a similarly illuminated white".
50
+ def to_rgb
51
+ chroma = (1 - (2 * @l - 1).abs) * @s
52
+ x = chroma * (1 - ((@h / 60.0) % 2.0 - 1).abs)
53
+ m = @l - chroma / 2.0
54
+
55
+ rgb = case
56
+ when @h == 0
57
+ Color.new(0, 0, 0)
58
+ when @h > 0 && @h < 60
59
+ Color.new(chroma, x, 0)
60
+ when @h > 60 && @h < 120
61
+ Color.new(x, chroma, 0)
62
+ when @h > 120 && @h < 180
63
+ Color.new(0, chroma, x)
64
+ when @h > 180 && @h < 240
65
+ Color.new(0, x, chroma)
66
+ when @h > 240 && @h < 300
67
+ Color.new(x, 0, chroma)
68
+ else
69
+ Color.new(chroma, 0, x)
70
+ end
71
+ Color.new(((rgb.red + m) * 255.0).round, ((rgb.green + m) * 255.0).round, ((rgb.blue + m) * 255.0).round)
72
+ end
73
+
74
+ def set_color(t1, t2, t3)
75
+ t3 += 1.0 if t3 < 0
76
+ t3 -= 1.0 if t3 > 1
77
+ case
78
+ when 6.0 * t3 < 1 then
79
+ t2 + (t1 - t2) * 6.0 * t3
80
+ when 2.0 * t3 < 1 then
81
+ t1
82
+ when 3.0 * t3 < 2 then
83
+ t2 + (t1 - t2) * ((2.0 / 3.0) - t3) * 6.0
84
+ else
85
+ t2
86
+ end
87
+ end
88
+
89
+ def calculate_lum_value(tint, lum)
90
+ if tint.nil?
91
+ lum
92
+ else
93
+ tint < 0 ? lum * (1.0 + tint) : lum * (1.0 - tint) + (255 - 255 * (1.0 - tint))
94
+ end
95
+ end
96
+
97
+ def self.calculate_with_luminance(color, lum_mod, lum_off = nil)
98
+ hls_color = color.is_a?(HSLColor) ? color : HSLColor.rgb_to_hsl(color)
99
+ # for hsl color which have h == 0 need another values of lumOff lumMod - 0.04(+-0.005)
100
+ if lum_mod
101
+ if hls_color.h == 0
102
+ hls_color.l *= case lum_mod
103
+ when 0.2
104
+ 0.169
105
+ when 0.4
106
+ 0.369
107
+ when 0.6
108
+ 0.55
109
+ when 0.75
110
+ 0.705
111
+ when 0.5
112
+ 0.469
113
+ else
114
+ lum_mod
115
+ end
116
+ else
117
+ hls_color.l *= lum_mod
118
+ end
119
+ end
120
+ current_rgb = hls_color.to_rgb
121
+ return current_rgb if current_rgb == Color.new
122
+
123
+ unless lum_off.nil?
124
+ hls_color = HSLColor.rgb_to_hsl(current_rgb)
125
+ # for hsl color which have h == 0 need another values of lumOff - 0.04(+-0.01)
126
+ if hls_color.h == 0
127
+ hls_color.l += case lum_off
128
+ when 0.8
129
+ 0.76
130
+ when 0.6
131
+ 0.55
132
+ when 0.4
133
+ 0.36
134
+ else
135
+ lum_off
136
+ end
137
+ else
138
+ hls_color.l += lum_off
139
+ end
140
+ current_rgb = hls_color.to_rgb
141
+ end
142
+ current_rgb
143
+ end
144
+
145
+ def calculate_rgb_with_tint(tint)
146
+ self.l = calculate_lum_value(tint, @l * 255.0) / 255.0
147
+ to_rgb
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,22 @@
1
+ module OoxmlParser
2
+ class FillRectangle
3
+ attr_accessor :left, :top, :right, :bottom
4
+
5
+ def self.parse(fill_rectangle_node)
6
+ fill_rectangle = FillRectangle.new
7
+ fill_rectangle_node.attributes.each do |key, value|
8
+ case key
9
+ when 'b'
10
+ fill_rectangle.bottom = value.value.to_i
11
+ when 't'
12
+ fill_rectangle.top = value.value.to_i
13
+ when 'l'
14
+ fill_rectangle.left = value.value.to_i
15
+ when 'r'
16
+ fill_rectangle.right = value.value.to_i
17
+ end
18
+ end
19
+ fill_rectangle
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module OoxmlParser
2
+ class Stretching
3
+ attr_accessor :fill_rectangle
4
+
5
+ def self.parse(stretch_node)
6
+ stretching = Stretching.new
7
+ stretching.fill_rectangle = FillRectangle.parse(stretch_node.xpath('a:fillRect').first) if stretch_node.xpath('a:fillRect').first
8
+ stretching
9
+ end
10
+ end
11
+ end