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.outlet;
031:
032: import de.intarsys.font.FontStyle;
033: import de.intarsys.pdf.encoding.Encoding;
034: import de.intarsys.pdf.font.PDFont;
035:
036: /**
037: * A query for requesting {@link PDFont} instances from an {@link IFontFactory}
038: * with the defined attributes.
039: *
040: */
041: public class FontQuery implements IFontQuery {
042: /**
043: * A template font defining defaults for the requested font.
044: */
045: private PDFont baseFont;
046:
047: /**
048: * The font style requested
049: */
050: private FontStyle overrideFontStyle = FontStyle.UNDEFINED;
051:
052: /**
053: * The font family requested
054: */
055: private String overrideFontFamilyName;
056:
057: /**
058: * The encoding requested
059: */
060: private Encoding overrideEncoding;
061:
062: /**
063: * Create a new {@link IFontQuery} based on another {@link PDFont}. USe the
064: * setter methods to overwrite the attributes you want to be different from
065: * <code>baseFont</code>.
066: *
067: * @param baseFont
068: * The font serivng as a template for this query.
069: */
070: public FontQuery(PDFont baseFont) {
071: super ();
072: this .baseFont = baseFont;
073: }
074:
075: /**
076: * Create a new {@link IFontQuery} denoting a font from the
077: * <code>family</code> in style <code>style</code>.
078: *
079: * @param baseFont
080: * The font serivng as a template for this query.
081: */
082: public FontQuery(String family, String style) {
083: super ();
084: setOverrideFontFamilyName(family);
085: setOverrideFontStyle(FontStyle.getFontStyle(style));
086: }
087:
088: /**
089: * Create a new {@link IFontQuery} denoting a font from the
090: * <code>family</code> in style <code>style</code>.
091: *
092: * @param baseFont
093: * The font serivng as a template for this query.
094: */
095: public FontQuery(String family, FontStyle style) {
096: super ();
097: setOverrideFontFamilyName(family);
098: setOverrideFontStyle(style);
099: }
100:
101: public Encoding getEncoding() {
102: if (getOverrideEncoding() == null) {
103: if (getBaseFont() == null) {
104: return null;
105: } else {
106: return getBaseFont().getEncoding();
107: }
108: } else {
109: return getOverrideEncoding();
110: }
111: }
112:
113: public String getFontFamilyName() {
114: if (getOverrideFontFamilyName() == null) {
115: if (getBaseFont() == null) {
116: return null;
117: } else {
118: return getBaseFont().getFontFamilyName();
119: }
120: } else {
121: return getOverrideFontFamilyName();
122: }
123: }
124:
125: public FontStyle getFontStyle() {
126: if (getOverrideFontStyle() == FontStyle.UNDEFINED) {
127: if (getBaseFont() == null) {
128: return FontStyle.UNDEFINED;
129: } else {
130: return getBaseFont().getFontStyle();
131: }
132: } else {
133: return getOverrideFontStyle();
134: }
135: }
136:
137: /**
138: * Set the encoding attribute for the font to be looked up.
139: *
140: * @param overrideEncoding
141: * The required encoding for the result font.
142: */
143: public void setOverrideEncoding(Encoding overrideEncoding) {
144: this .overrideEncoding = overrideEncoding;
145: }
146:
147: /**
148: * The required encoding for the result font.
149: *
150: * @return The required encoding for the result font.
151: */
152: public Encoding getOverrideEncoding() {
153: return overrideEncoding;
154: }
155:
156: /**
157: * Set the font family attribute for the font to be looked up.
158: *
159: * @param overrideFontFamilyName
160: * The required font family for the result font.
161: */
162: public void setOverrideFontFamilyName(String overrideFontFamilyName) {
163: this .overrideFontFamilyName = overrideFontFamilyName;
164: }
165:
166: /**
167: * The required font family for the result font.
168: *
169: * @return The required font family for the result font.
170: */
171: public String getOverrideFontFamilyName() {
172: return overrideFontFamilyName;
173: }
174:
175: /**
176: * Set the font style attribute for the font to be looked up.
177: *
178: * @param overrideFontStyle
179: * The required font style for the result font.
180: */
181: public void setOverrideFontStyle(FontStyle overrideFontStyle) {
182: this .overrideFontStyle = overrideFontStyle;
183: }
184:
185: /**
186: * The required font style for the result font.
187: *
188: * @return The required font style for the result font.
189: */
190: public FontStyle getOverrideFontStyle() {
191: return overrideFontStyle;
192: }
193:
194: protected PDFont getBaseFont() {
195: return baseFont;
196: }
197:
198: protected boolean checkLastChar() {
199: return getBaseFont() != null;
200: }
201: }
|