1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28: 29: 30:
31: class PHPWord_Style
32: {
33:
34: 35: 36: 37: 38:
39: private static $_styleElements = array();
40:
41:
42: 43: 44: 45: 46: 47:
48: public static function addParagraphStyle($styleName, $styles)
49: {
50: if (!array_key_exists($styleName, self::$_styleElements)) {
51: $style = new PHPWord_Style_Paragraph();
52: foreach ($styles as $key => $value) {
53: if (substr($key, 0, 1) != '_') {
54: $key = '_' . $key;
55: }
56: $style->setStyleValue($key, $value);
57: }
58:
59: self::$_styleElements[$styleName] = $style;
60: }
61: }
62:
63: 64: 65: 66: 67: 68: 69:
70: public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
71: {
72: if (!array_key_exists($styleName, self::$_styleElements)) {
73: $font = new PHPWord_Style_Font('text', $styleParagraph);
74: foreach ($styleFont as $key => $value) {
75: if (substr($key, 0, 1) != '_') {
76: $key = '_' . $key;
77: }
78: $font->setStyleValue($key, $value);
79: }
80: self::$_styleElements[$styleName] = $font;
81: }
82: }
83:
84: 85: 86: 87: 88: 89:
90: public static function addLinkStyle($styleName, $styles)
91: {
92: if (!array_key_exists($styleName, self::$_styleElements)) {
93: $style = new PHPWord_Style_Font('link');
94: foreach ($styles as $key => $value) {
95: if (substr($key, 0, 1) != '_') {
96: $key = '_' . $key;
97: }
98: $style->setStyleValue($key, $value);
99: }
100:
101: self::$_styleElements[$styleName] = $style;
102: }
103: }
104:
105: 106: 107: 108: 109: 110:
111: public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null)
112: {
113: if (!array_key_exists($styleName, self::$_styleElements)) {
114: $style = new PHPWord_Style_TableFull($styleTable, $styleFirstRow, $styleLastRow);
115:
116: self::$_styleElements[$styleName] = $style;
117: }
118: }
119:
120: 121: 122: 123: 124: 125: 126:
127: public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
128: {
129: $styleName = 'Heading_' . $titleCount;
130: if (!array_key_exists($styleName, self::$_styleElements)) {
131: $font = new PHPWord_Style_Font('title', $styleParagraph);
132: foreach ($styleFont as $key => $value) {
133: if (substr($key, 0, 1) != '_') {
134: $key = '_' . $key;
135: }
136: $font->setStyleValue($key, $value);
137: }
138:
139: self::$_styleElements[$styleName] = $font;
140: }
141: }
142:
143: 144: 145: 146: 147:
148: public static function getStyles()
149: {
150: return self::$_styleElements;
151: }
152:
153: 154: 155: 156: 157: 158:
159: public static function getStyle($styleName)
160: {
161: if (array_key_exists($styleName, self::$_styleElements)) {
162: return self::$_styleElements[$styleName];
163: } else {
164: return null;
165: }
166: }
167: }
168:
169: