001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.font;
031:
032: import de.intarsys.font.FontStyle;
033: import de.intarsys.pdf.cos.COSName;
034: import de.intarsys.pdf.cos.COSObject;
035:
036: /**
037: * A CID indexed font.
038: * <p>
039: * This is a wrapper around a Type 1 or TrueType Font that is indexed using
040: * CID's.
041: * <p>
042: * This is a a subclass of PDFont only for implementation reasons.
043: * <p>
044: * todo 1 cmap review, delegate methods, access implementation font.
045: */
046: abstract public class CIDFont extends PDFont {
047: public static final COSName DK_CIDSystemInfo = COSName
048: .constant("CIDSystemInfo");
049:
050: public static final COSName DK_DW = COSName.constant("DW");
051:
052: public static final COSName DK_W = COSName.constant("W");
053:
054: public static final COSName DK_DW2 = COSName.constant("DW2");
055:
056: public static final COSName DK_W2 = COSName.constant("W2");
057:
058: /**
059: * The meta class implementation
060: */
061: static public class MetaClass extends PDFont.MetaClass {
062: protected MetaClass(Class instanceClass) {
063: super (instanceClass);
064: }
065: }
066:
067: /** The meta class instance */
068: static public final MetaClass META = new MetaClass(MetaClass.class
069: .getDeclaringClass());
070:
071: protected CIDFont(COSObject object) {
072: super (object);
073: }
074:
075: private CIDWidthMap map = null;
076:
077: public CIDWidthMap getCIDWidthMap() {
078: if (map == null) {
079: map = CIDWidthMap.createMap(cosGetField(DK_W).asArray());
080: }
081: return map;
082: }
083:
084: /*
085: * (non-Javadoc)
086: *
087: * @see de.intarsys.font.IFont#getFontFamilyName()
088: */
089: public String getFontFamilyName() {
090: return "Helvetica";
091: }
092:
093: public String getFontName() {
094: return "Helvetica";
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see de.intarsys.font.IFont#getFontStyle()
101: */
102: public FontStyle getFontStyle() {
103: return FontStyle.REGULAR;
104: }
105:
106: /*
107: * (non-Javadoc)
108: *
109: * @see de.intarsys.pdf.font.PDFont#getUnderlinePosition()
110: */
111: public float getUnderlinePosition() {
112: return 0;
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see de.intarsys.pdf.font.PDFont#getUnderlineThickness()
119: */
120: public int getUnderlineThickness() {
121: return 0;
122: }
123:
124: /*
125: * (non-Javadoc)
126: *
127: * @see de.intarsys.pdf.font.PDFont#createBuiltinFontDescriptor()
128: */
129: protected PDFontDescriptor createBuiltinFontDescriptor() {
130: return null;
131: }
132:
133: public CIDSystemInfo getCIDSystemInfo() {
134: return (CIDSystemInfo) CIDSystemInfo.META
135: .createFromCos(cosGetField(DK_CIDSystemInfo));
136: }
137:
138: /*
139: * (non-Javadoc)
140: *
141: * @see de.intarsys.pdf.font.PDFont#getGlyphWidth(int)
142: */
143: public int getGlyphWidth(int cidValue) {
144: int width = getCIDWidthMap().getWidth(cidValue);
145: if (width == -1) {
146: width = getFieldInt(DK_DW, 1000);
147: }
148: return width;
149: }
150:
151: abstract public int getGlyphIndex(CID cid);
152: }
|