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: /* $Id: RtfListStyleText.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.rtf.rtflib.rtfdoc;
021:
022: /*
023: * This file is part of the RTF library of the FOP project, which was originally
024: * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
025: * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
026: * the FOP project.
027: */
028:
029: //Java
030: import java.io.IOException;
031:
032: //FOP
033: import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement;
034:
035: /**
036: * Class to handle text list style.
037: */
038: public class RtfListStyleText extends RtfListStyle {
039: private String text;
040:
041: /**
042: * Constructs a RtfListStyleText object.
043: * @param s Text to be displayed
044: */
045: public RtfListStyleText(String s) {
046: text = s;
047: }
048:
049: /**
050: * Gets called before a RtfListItem has to be written.
051: * @param item RtfListItem whose prefix has to be written
052: * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListStyle#writeListPrefix(RtfListItem)
053: * @throws IOException Thrown when an IO-problem occurs
054: */
055: public void writeListPrefix(RtfListItem item) throws IOException {
056: // bulleted list
057: item.writeControlWord("pnlvlblt");
058: item.writeControlWord("ilvl0");
059: item.writeOneAttribute(RtfListTable.LIST_NUMBER, new Integer(
060: item.getNumber()));
061: item.writeOneAttribute("pnindent", item.getParentList().attrib
062: .getValue(RtfListTable.LIST_INDENT));
063: item.writeControlWord("pnf1");
064: item.writeGroupMark(true);
065: //item.writeControlWord("pndec");
066: item.writeOneAttribute(RtfListTable.LIST_FONT_TYPE, "2");
067: item.writeControlWord("pntxtb");
068: RtfStringConverter.getInstance().writeRtfString(item.writer,
069: text);
070: item.writeGroupMark(false);
071: }
072:
073: /**
074: * Gets called before a paragraph, which is contained by a RtfListItem has to be written.
075: *
076: * @param element RtfElement in whose context is to be written
077: * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListStyle#writeParagraphPrefix(RtfElement)
078: * @throws IOException Thrown when an IO-problem occurs
079: */
080: public void writeParagraphPrefix(RtfElement element)
081: throws IOException {
082: element.writeGroupMark(true);
083: element.writeControlWord("pntext");
084: element.writeGroupMark(false);
085: }
086:
087: /**
088: * Gets called when the list table has to be written.
089: *
090: * @param element RtfElement in whose context is to be written
091: * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListStyle#writeLevelGroup(RtfElement)
092: * @throws IOException Thrown when an IO-problem occurs
093: */
094: public void writeLevelGroup(RtfElement element) throws IOException {
095: element.attrib.set(RtfListTable.LIST_NUMBER_TYPE, 23);
096: element.writeGroupMark(true);
097:
098: String sCount;
099: if (text.length() < 10) {
100: sCount = "0" + String.valueOf(text.length());
101: } else {
102: sCount = String.valueOf(Integer.toHexString(text.length()));
103: if (sCount.length() == 1) {
104: sCount = "0" + sCount;
105: }
106: }
107: element.writeOneAttributeNS(RtfListTable.LIST_TEXT_FORM, "\\'"
108: + sCount
109: + RtfStringConverter.getInstance().escape(text));
110: element.writeGroupMark(false);
111:
112: element.writeGroupMark(true);
113: element.writeOneAttributeNS(RtfListTable.LIST_NUM_POSITION,
114: null);
115: element.writeGroupMark(false);
116:
117: element.attrib.set(RtfListTable.LIST_FONT_TYPE, 2);
118: }
119: }
|