21package org.openoffice.xmerge.converter.xml;
25import org.w3c.dom.NodeList;
26import org.w3c.dom.Node;
27import org.w3c.dom.NamedNodeMap;
28import org.w3c.dom.Element;
38 final private static int BOLD = 0x01;
40 final private static int ITALIC = 0x02;
78 NamedNodeMap attrNodes = node.getAttributes();
79 if (attrNodes !=
null) {
80 int len = attrNodes.getLength();
81 for (
int i = 0;
i < len;
i++) {
82 Node attr = attrNodes.item(
i);
90 if (!node.hasChildNodes()) {
93 NodeList children = node.getChildNodes();
94 int len = children.getLength();
95 for (
int i = 0;
i < len;
i++) {
96 Node child = children.item(
i);
97 String nodeName = child.getNodeName();
98 if (nodeName.equals(
"style:properties")) {
99 NamedNodeMap childAttrNodes = child.getAttributes();
100 if (childAttrNodes !=
null) {
101 int nChildAttrNodes = childAttrNodes.getLength();
102 for (
int j = 0; j < nChildAttrNodes; j++) {
103 Node attr = childAttrNodes.item(j);
105 attr.getNodeValue());
143 this.sizeInPoints = fontSize;
163 }
catch (NumberFormatException e) {
165 }
catch (IndexOutOfBoundsException e) {
168 return new Color(red, green, blue);
179 if (attr.equals(
"fo:font-weight")) {
184 else if (attr.equals(
"fo:font-style")) {
190 else if (attr.equals(
"style:text-underline")) {
191 if (
value.equals(
"none"))
197 else if (attr.equals(
"style:text-crossing-out")) {
198 if (
value.equals(
"none"))
204 else if (attr.equals(
"style:text-position")) {
205 if (
value.startsWith(
"super "))
207 else if (
value.startsWith(
"sub "))
209 else if (
value.startsWith(
"0% "))
213 if (firstPart.endsWith(
"%")) {
214 firstPart = firstPart.substring(0,
value.indexOf(
'%'));
217 amount =
Integer.parseInt(firstPart);
218 }
catch (NumberFormatException e) {
228 else if (attr.equals(
"fo:font-size")) {
229 if (
value.endsWith(
"pt")) {
235 else if (attr.equals(
"style:font-name"))
238 else if (attr.equals(
"fo:color"))
241 else if (attr.equals(
"style:text-background-color"))
319 if (parentStyle ==
null)
325 }
else if (!
name.equals(
"DEFAULT_STYLE")) {
326 parentStyle = (
TextStyle)
sc.lookup(
"DEFAULT_STYLE",
null,
327 null,
this.getClass());
333 if (parentStyle !=
null) {
345 if (((
mask &
m) == 0) && ((parentStyle.
mask &
m) != 0)) {
385 return "\"" +
value +
"\",";
400 return "\"" +
value +
"\"";
419 StringBuilder attributes =
new StringBuilder();
420 for (
int bitVal = 0x01; bitVal <= 0x20; bitVal = bitVal << 1) {
421 if ((bitVal &
mask) != 0) {
422 attributes.append(
toCSV(((bitVal &
values) != 0) ?
"yes" :
"no"));
425 attributes.append(
toCSV(
null));
444 Element node = parentDoc.createElement(
name);
460 if (style.getClass() !=
this.getClass())
503 node.setAttribute(
"fo:font-weight",
"bold");
506 node.setAttribute(
"fo:font-style",
"italic");
509 node.setAttribute(
"style:text-underline",
"single");
512 node.setAttribute(
"style:text-crossing-out",
"single-line");
515 node.setAttribute(
"style:text-position",
"super 58%");
518 node.setAttribute(
"style:text-position",
"sub 58%");
525 node.setAttribute(
"style:font-name",
fontName);
531 node.setAttribute(
"style:text-background-color",
543 return String.format(
"#%06X", c.getRGB() & 0x00FFFFFF);
547 "style:text-autospace",
"style:text-underline-color",
548 "fo:margin-left",
"fo:margin-right",
"fo:text-indent",
549 "fo:margin-top",
"fo:margin-bottom",
"text:line-number",
550 "text:number-lines",
"style:country-asian",
551 "style:font-size-asian",
"style:font-name-complex",
552 "style:language-complex",
"style:country-complex",
553 "style:font-size-complex",
"style:punctuation-wrap",
554 "fo:language",
"fo:country",
555 "style:font-name-asian",
"style:language-asian",
556 "style:line-break",
"fo:keep-with-next"
A StyleCatalog holds a collection of Style objects.
An object of class Style represents a style in an OpenOffice document.
String parent
Parent of the Style.
String family
Family of the Style.
String name
Name of the Style.
Represents a text Style in an OpenOffice document.
boolean isSubset(Style style)
Return true if style specifies as much or less than this Style, and nothing it specifies contradicts ...
String fontName
Font name.
final static int ITALIC
Indicates italic text.
String getFontName()
Return the name of the font for this Style.
Color getBackgroundColor()
Return the background Color for this Style.
void handleAttribute(String attr, String value)
Set an attribute.
boolean isIgnored(String attribute)
This code checks whether an attribute is one that we intentionally ignore.
int values
Values of text attributes.
static String toCSV(String value)
Private function to return the value as an element in a Comma Separated Value (CSV) format.
Style getResolved()
Return a Style object corresponding to this one, but with all of the inherited information from paren...
Color parseColorString(String value)
Parse a color specification of the form #rrggbb
TextStyle(Node node, StyleCatalog sc)
Constructor for use when going from DOM to client device format.
void writeAttributes(Element node)
Write this Style object's attributes to a Node in the Document.
Color fontColor
Font Color.
int mask
Bitwise mask of text attributes.
void dumpCSV()
Dump this Style as a Comma Separated Value (CSV) line.
void turnAttributesOff(int flags)
Set one or more text attributes to off.
void turnAttributesOn(int flags)
Set one or more text attributes to on.
final static int STRIKETHRU
Indicates strike-through in the text.
TextStyle(String name, String family, String parent, int mask, int values, int fontSize, String fontName, StyleCatalog sc)
Constructor for use when going from client device format to DOM.
int sizeInPoints
Font size in points.
final static int SUBSCRIPT
Indicates subscripted text.
final static int BOLD
Indicates bold text.
Color bgColor
Background Color.
Node createNode(org.w3c.dom.Document parentDoc, String name)
Create a new Node in the Document, and write this Style to it.
int getFontSize()
Return the font size for this Style.
final static int UNDERLINE
Indicates underlined text.
static void dumpHdr()
Print a Comma Separated Value (CSV) header line for the spreadsheet dump.
String buildColorString(Color c)
Given a Color, return a string of the form #rrggbb.
final static int SUPERSCRIPT
Indicates superscripted text.
static String toLastCSV(String value)
Private function to return the value as a last element in a Comma Separated Value (CSV) format.
Color getFontColor()
Return the font Color for this Style.
This class is used for logging debug messages.
static final int INFO
Informational messages.
static void log(int flag, String msg)
Log message based on the flag type.
static final int ERROR
Error messages.
T * clone(T *const other)
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...