001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.dev;
019:
020: import org.apache.poi.hslf.*;
021: import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
022: import org.apache.poi.hslf.model.textproperties.TextProp;
023: import org.apache.poi.hslf.model.textproperties.TextPropCollection;
024: import org.apache.poi.hslf.record.*;
025: import org.apache.poi.hslf.record.StyleTextPropAtom.*;
026:
027: import java.util.LinkedList;
028:
029: /**
030: * Uses record level code to locate StyleTextPropAtom entries.
031: * Having found them, it shows the contents
032: */
033: public class TextStyleListing {
034: public static void main(String[] args) throws Exception {
035: if (args.length < 1) {
036: System.err.println("Need to give a filename");
037: System.exit(1);
038: }
039:
040: HSLFSlideShow ss = new HSLFSlideShow(args[0]);
041:
042: // Find the documents, and then their SLWT
043: Record[] records = ss.getRecords();
044: for (int i = 0; i < records.length; i++) {
045: if (records[i].getRecordType() == 1000l) {
046: Record docRecord = records[i];
047: Record[] docChildren = docRecord.getChildRecords();
048: for (int j = 0; j < docChildren.length; j++) {
049: if (docChildren[j] instanceof SlideListWithText) {
050: Record[] slwtChildren = docChildren[j]
051: .getChildRecords();
052:
053: int lastTextLen = -1;
054: for (int k = 0; k < slwtChildren.length; k++) {
055: if (slwtChildren[k] instanceof TextCharsAtom) {
056: lastTextLen = ((TextCharsAtom) slwtChildren[k])
057: .getText().length();
058: }
059: if (slwtChildren[k] instanceof TextBytesAtom) {
060: lastTextLen = ((TextBytesAtom) slwtChildren[k])
061: .getText().length();
062: }
063:
064: if (slwtChildren[k] instanceof StyleTextPropAtom) {
065: StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChildren[k];
066: stpa.setParentTextSize(lastTextLen);
067: showStyleTextPropAtom(stpa);
068: }
069: }
070: }
071: }
072: }
073: }
074: }
075:
076: public static void showStyleTextPropAtom(StyleTextPropAtom stpa) {
077: System.out.println("\nFound a StyleTextPropAtom");
078:
079: LinkedList paragraphStyles = stpa.getParagraphStyles();
080: System.out.println("Contains " + paragraphStyles.size()
081: + " paragraph styles:");
082: for (int i = 0; i < paragraphStyles.size(); i++) {
083: TextPropCollection tpc = (TextPropCollection) paragraphStyles
084: .get(i);
085: System.out.println(" In paragraph styling " + i + ":");
086: System.out.println(" Characters covered is "
087: + tpc.getCharactersCovered());
088: showTextProps(tpc);
089: }
090:
091: LinkedList charStyles = stpa.getCharacterStyles();
092: System.out.println("Contains " + charStyles.size()
093: + " character styles:");
094: for (int i = 0; i < charStyles.size(); i++) {
095: TextPropCollection tpc = (TextPropCollection) charStyles
096: .get(i);
097: System.out.println(" In character styling " + i + ":");
098: System.out.println(" Characters covered is "
099: + tpc.getCharactersCovered());
100: showTextProps(tpc);
101: }
102: }
103:
104: public static void showTextProps(TextPropCollection tpc) {
105: LinkedList textProps = tpc.getTextPropList();
106: System.out.println(" Contains " + textProps.size()
107: + " TextProps");
108: for (int i = 0; i < textProps.size(); i++) {
109: TextProp tp = (TextProp) textProps.get(i);
110: System.out.println(" " + i + " - " + tp.getName());
111: System.out.println(" = " + tp.getValue());
112: System.out.println(" @ " + tp.getMask());
113:
114: if (tp instanceof BitMaskTextProp) {
115: BitMaskTextProp bmtp = (BitMaskTextProp) tp;
116: String[] subPropNames = bmtp.getSubPropNames();
117: boolean[] subPropMatches = bmtp.getSubPropMatches();
118: for (int j = 0; j < subPropNames.length; j++) {
119: System.out.println(" -> " + j + " - "
120: + subPropNames[j]);
121: System.out.println(" " + j + " = "
122: + subPropMatches[j]);
123: }
124: }
125: }
126: }
127: }
|