001package com.hfg.xml.msofficexml.docx.wordprocessingml.style;
002
003
004import java.awt.Color;
005import java.util.ArrayList;
006import java.util.List;
007
008import com.hfg.graphics.units.Points;
009import com.hfg.xml.msofficexml.docx.Docx;
010import com.hfg.xml.msofficexml.docx.wordprocessingml.WmlTextRunProperties;
011import com.hfg.xml.msofficexml.docx.wordprocessingml.WmlXML;
012
013//------------------------------------------------------------------------------
014/**
015 Character style for Docx's Office Open XML documents.
016
017 @author J. Alex Taylor, hairyfatguy.com
018 */
019//------------------------------------------------------------------------------
020// com.hfg XML/HTML Coding Library
021//
022// This library is free software; you can redistribute it and/or
023// modify it under the terms of the GNU Lesser General Public
024// License as published by the Free Software Foundation; either
025// version 2.1 of the License, or (at your option) any later version.
026//
027// This library is distributed in the hope that it will be useful,
028// but WITHOUT ANY WARRANTY; without even the implied warranty of
029// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
030// Lesser General Public License for more details.
031//
032// You should have received a copy of the GNU Lesser General Public
033// License along with this library; if not, write to the Free Software
034// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
035//
036// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
037// jataylor@hairyfatguy.com
038//------------------------------------------------------------------------------
039
040public class WmlCharacterStyle extends WmlStyle
041{
042   public static final String DEFAULT_PARAGRAPH_FONT_STYLE_ID = "DefaultParagraphFont";
043   public static final String HYPERLINK_STYLE_ID              = "Hyperlink";
044   public static final String HEADING1_CHAR_STYLE_ID          = "Heading1Char";
045   public static final String HEADING2_CHAR_STYLE_ID          = "Heading2Char";
046
047   private WmlTextRunProperties mRunProperties;
048
049   //##########################################################################
050   // CONSTRUCTORS
051   //##########################################################################
052
053   //---------------------------------------------------------------------------
054   public WmlCharacterStyle(Docx inDocx)
055   {
056      super(WmlStyleType.character, inDocx);
057   }
058
059   //---------------------------------------------------------------------------
060   public WmlCharacterStyle(String inId, Docx inDocx)
061   {
062      super(WmlStyleType.character, inId, inDocx);
063   }
064
065   //##########################################################################
066   // PUBLIC METHODS
067   //##########################################################################
068
069   //---------------------------------------------------------------------------
070   @Override
071   public WmlCharacterStyle setName(String inValue)
072   {
073      return (WmlCharacterStyle) super.setName(inValue);
074   }
075
076   //---------------------------------------------------------------------------
077   @Override
078   public WmlCharacterStyle setBasedOn(String inStyleId)
079   {
080      return (WmlCharacterStyle) super.setBasedOn(inStyleId);
081   }
082
083   //---------------------------------------------------------------------------
084   @Override
085   public WmlCharacterStyle setLink(String inStyleId)
086   {
087      return (WmlCharacterStyle) super.setLink(inStyleId);
088   }
089
090   //---------------------------------------------------------------------------
091   @Override
092   public WmlCharacterStyle setUI_Priority(Integer inValue)
093   {
094      return (WmlCharacterStyle) super.setUI_Priority(inValue);
095   }
096
097   //---------------------------------------------------------------------------
098   @Override
099   public WmlCharacterStyle setSemiHidden()
100   {
101      return (WmlCharacterStyle) super.setSemiHidden();
102   }
103
104   //---------------------------------------------------------------------------
105   @Override
106   public WmlCharacterStyle setUnhideWhenUsed()
107   {
108      return (WmlCharacterStyle) super.setUnhideWhenUsed();
109   }
110
111   //---------------------------------------------------------------------------
112   /**
113    * Returns the run properties tag if one exists or else instantiates a new one.
114    * @return the run properties for this table
115    */
116   public WmlTextRunProperties getRunProperties()
117   {
118      if (null == mRunProperties)
119      {
120         // Check it it has been added via addSubtag()...
121         mRunProperties = (WmlTextRunProperties) getOptionalSubtagByName(WmlXML.RUN_PROPS);
122         if (null == mRunProperties)
123         {
124            mRunProperties = new WmlTextRunProperties(getParentDoc());
125            addSubtag(0, mRunProperties);
126         }
127      }
128
129      return mRunProperties;
130   }
131
132
133   //---------------------------------------------------------------------------
134   public static List<WmlStyle> generateDefaultStyles(Docx inParentDoc)
135   {
136      List<WmlStyle> defaultStyles = new ArrayList<>(5);
137
138      // Default Paragraph Font
139      defaultStyles.add(new WmlCharacterStyle(DEFAULT_PARAGRAPH_FONT_STYLE_ID, inParentDoc)
140                              .setName("Default Paragraph Font")
141                              .setIsDefault(true)
142                              .setSemiHidden()
143                              .setUnhideWhenUsed());
144
145      // Hyperlink
146      defaultStyles.add(generateHyperlink(inParentDoc));
147
148      // Heading 1 Char
149      defaultStyles.add(generateHeading1Char(inParentDoc));
150
151      // Heading 2 Char
152      defaultStyles.add(generateHeading2Char(inParentDoc));
153
154      return defaultStyles;
155   }
156
157   //##########################################################################
158   // PRIVATE METHODS
159   //##########################################################################
160
161   //---------------------------------------------------------------------------
162   /*
163     <w:style w:type="character" w:styleId="Hyperlink">
164        <w:name w:val="Hyperlink"/>
165        <w:basedOn w:val="DefaultParagraphFont"/>
166        <w:uiPriority w:val="99"/>
167        <w:unhideWhenUsed/>
168        <w:rsid w:val="00463183"/>
169        <w:rPr>
170           <w:color w:val="0563C1" w:themeColor="hyperlink"/>
171           <w:u w:val="single"/>
172        </w:rPr>
173     </w:style>
174    */
175   private static WmlCharacterStyle generateHyperlink(Docx inParentDoc)
176   {
177      WmlCharacterStyle style = new WmlCharacterStyle(HYPERLINK_STYLE_ID, inParentDoc)
178            .setName("Hyperlink")
179            .setBasedOn(DEFAULT_PARAGRAPH_FONT_STYLE_ID)
180            .setUI_Priority(99)
181            .setUnhideWhenUsed();
182
183      style.getTextRunProperties()
184            .setColor(Color.decode("#0563C1"))
185            .setThemeColor("hyperlink")
186            .setUnderline();
187
188      return style;
189   }
190
191   //---------------------------------------------------------------------------
192   /*
193     <w:style w:type="character" w:customStyle="1" w:styleId="Heading1Char">
194        <w:name w:val="Heading 1 Char"/>
195        <w:basedOn w:val="DefaultParagraphFont"/>
196        <w:link w:val="Heading1"/>
197        <w:uiPriority w:val="9"/>
198        <w:rsid w:val="00463183"/>
199        <w:rPr>
200           <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi"/>
201           <w:color w:val="2F5496" w:themeColor="accent1" w:themeShade="BF"/>
202           <w:sz w:val="32"/>
203           <w:szCs w:val="32"/>
204        </w:rPr>
205     </w:style>
206    */
207   private static WmlCharacterStyle generateHeading1Char(Docx inParentDoc)
208   {
209      WmlCharacterStyle style = new WmlCharacterStyle(HEADING1_CHAR_STYLE_ID, inParentDoc)
210            .setName("Heading 1 Char")
211            .setBasedOn(DEFAULT_PARAGRAPH_FONT_STYLE_ID)
212            .setLink(WmlParagraphStyle.HEADING1_STYLE_ID)
213            .setUI_Priority(9);
214
215      style.getTextRunProperties()
216            .setAnsiThemeFont("majorHAnsi")
217            .setAsciiThemeFont("majorHAnsi")
218            .setComplexScriptThemeFont("majorBidi")
219            .setEastAsiaThemeFont("majorEastAsia")
220            .setColor(Color.decode("#2F5496"))
221            .setThemeColor("accent1")
222            .setThemeShade("BF")
223            .setSize(new Points(16))
224            .setComplexScriptSize(new Points(16));
225
226      return style;
227   }
228
229   //---------------------------------------------------------------------------
230   /*
231     <w:style w:type="character" w:customStyle="1" w:styleId="Heading1Char">
232        <w:name w:val="Heading 1 Char"/>
233        <w:basedOn w:val="DefaultParagraphFont"/>
234        <w:link w:val="Heading1"/>
235        <w:uiPriority w:val="9"/>
236        <w:rsid w:val="00463183"/>
237        <w:rPr>
238           <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi"/>
239           <w:color w:val="2F5496" w:themeColor="accent1" w:themeShade="BF"/>
240           <w:sz w:val="32"/>
241           <w:szCs w:val="32"/>
242        </w:rPr>
243     </w:style>
244    */
245   private static WmlCharacterStyle generateHeading2Char(Docx inParentDoc)
246   {
247      WmlCharacterStyle style = new WmlCharacterStyle(HEADING2_CHAR_STYLE_ID, inParentDoc)
248            .setName("Heading 2 Char")
249            .setBasedOn(DEFAULT_PARAGRAPH_FONT_STYLE_ID)
250            .setLink(WmlParagraphStyle.HEADING2_STYLE_ID)
251            .setUI_Priority(9);
252
253      style.getTextRunProperties()
254            .setAnsiThemeFont("majorHAnsi")
255            .setAsciiThemeFont("majorHAnsi")
256            .setComplexScriptThemeFont("majorBidi")
257            .setEastAsiaThemeFont("majorEastAsia")
258            .setColor(Color.decode("#2F5496"))
259            .setThemeColor("accent1")
260            .setThemeShade("BF")
261            .setSize(new Points(13))
262            .setComplexScriptSize(new Points(13));
263
264      return style;
265   }
266}
267/*
268
269 */