diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-03-27 14:03:16 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-03-27 14:03:16 +0000 |
commit | 37791e4bdfc706aa5684745594260f243b4be7ee (patch) | |
tree | a8dd8d0976fc478074d52cd3de79e0e6b5e6a33a /src/java/org/apache/poi/common/usermodel/fonts | |
parent | 2bb3839bfe3e3bacff79f8157465633e311239ce (diff) | |
download | poi-37791e4bdfc706aa5684745594260f243b4be7ee.tar.gz poi-37791e4bdfc706aa5684745594260f243b4be7ee.zip |
65206 - Migrate ant / maven to gradle build
update gradle files and project structure along https://github.com/centic9/poi/tree/gradle_build
remove eclipse IDE project files
remove obsolete record generator files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1888111 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/common/usermodel/fonts')
7 files changed, 0 insertions, 1056 deletions
diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java b/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java deleted file mode 100644 index 044765738f..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java +++ /dev/null @@ -1,125 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -import java.nio.charset.Charset; -import java.nio.charset.UnsupportedCharsetException; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * Charset represents the basic set of characters associated with a font (that it can display), and - * corresponds to the ANSI codepage (8-bit or DBCS) of that character set used by a given language. - * - * @since POI 3.17-beta2 - */ -@SuppressWarnings("java:S1192") -public enum FontCharset { - /** Specifies the English character set. */ - ANSI(0x00000000, "Cp1252"), - /** - * Specifies a character set based on the current system locale; - * for example, when the system locale is United States English, - * the default character set is ANSI_CHARSET. - */ - DEFAULT(0x00000001, "Cp1252"), - /** Specifies a character set of symbols. */ - SYMBOL(0x00000002, ""), - /** Specifies the Apple Macintosh character set. */ - MAC(0x0000004D, "MacRoman"), - /** Specifies the Japanese character set. */ - SHIFTJIS(0x00000080, "Shift_JIS"), - /** Also spelled "Hangeul". Specifies the Hangul Korean character set. */ - HANGUL(0x00000081, "cp949"), - /** Also spelled "Johap". Specifies the Johab Korean character set. */ - JOHAB(0x00000082, "x-Johab"), - /** Specifies the "simplified" Chinese character set for People's Republic of China. */ - GB2312(0x00000086, "GB2312"), - /** - * Specifies the "traditional" Chinese character set, used mostly in - * Taiwan and in the Hong Kong and Macao Special Administrative Regions. - */ - CHINESEBIG5(0x00000088, "Big5"), - /** Specifies the Greek character set. */ - GREEK(0x000000A1, "Cp1253"), - /** Specifies the Turkish character set. */ - TURKISH(0x000000A2, "Cp1254"), - /** Specifies the Vietnamese character set. */ - VIETNAMESE(0x000000A3, "Cp1258"), - /** Specifies the Hebrew character set. */ - HEBREW(0x000000B1, "Cp1255"), - /** Specifies the Arabic character set. */ - ARABIC(0x000000B2, "Cp1256"), - /** Specifies the Baltic (Northeastern European) character set. */ - BALTIC(0x000000BA, "Cp1257"), - /** Specifies the Russian Cyrillic character set. */ - RUSSIAN(0x000000CC, "Cp1251"), - /** Specifies the Thai character set. */ - THAI(0x000000DE, "x-windows-874"), - /** Specifies a Eastern European character set. */ - EASTEUROPE(0x000000EE, "Cp1250"), - /** - * Specifies a mapping to one of the OEM code pages, - * according to the current system locale setting. - */ - OEM(0x000000FF, "Cp1252"); - - private static FontCharset[] _table = new FontCharset[256]; - - private int nativeId; - private Charset charset; - - - static { - for (FontCharset c : values()) { - _table[c.getNativeId()] = c; - } - } - - FontCharset(int flag, String javaCharsetName) { - this.nativeId = flag; - if (javaCharsetName.length() > 0) { - try { - charset = Charset.forName(javaCharsetName); - return; - } catch (UnsupportedCharsetException e) { - Logger logger = LogManager.getLogger(FontCharset.class); - logger.atWarn().log("Unsupported charset: {}", javaCharsetName); - } - } - charset = null; - } - - /** - * - * @return charset for the font or <code>null</code> if there is no matching charset or - * if the charset is a "default" - */ - public Charset getCharset() { - return charset; - } - - public int getNativeId() { - return nativeId; - } - - public static FontCharset valueOf(int value){ - return (value < 0 || value >= _table.length) ? null : _table[value]; - } -}
\ No newline at end of file diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontFacet.java b/src/java/org/apache/poi/common/usermodel/fonts/FontFacet.java deleted file mode 100644 index 5fb16908cd..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontFacet.java +++ /dev/null @@ -1,75 +0,0 @@ -/* ==================================================================== -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -import org.apache.poi.util.Beta; - -/** - * A FontFacet holds the font data for a shape of a font, i.e. a regular, - * italic, bold or bold-italic version of a Font. - */ -@SuppressWarnings("unused") -@Beta -public interface FontFacet { - /** - * Get the font weight.<p> - * - * The weight of the font in the range 0 through 1000. - * For example, 400 is normal and 700 is bold. - * If this value is zero, a default weight is used. - * - * @return the font weight - * - * @since POI 4.1.0 - */ - default int getWeight() { - return FontHeader.REGULAR_WEIGHT; - } - - /** - * Set the font weight - * - * @param weight the font weight - */ - default void setWeight(int weight) { - throw new UnsupportedOperationException("FontFacet is read-only."); - } - - /** - * @return {@code true}, if the font is italic - */ - default boolean isItalic() { - return false; - } - - /** - * Set the font posture - * - * @param italic {@code true} for italic, {@code false} for regular - */ - default void setItalic(boolean italic) { - throw new UnsupportedOperationException("FontFacet is read-only."); - } - - /** - * @return the wrapper object holding the font data - */ - default Object getFontData() { - return null; - } -} diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontFamily.java b/src/java/org/apache/poi/common/usermodel/fonts/FontFamily.java deleted file mode 100644 index b627e10af8..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontFamily.java +++ /dev/null @@ -1,82 +0,0 @@ -/* ==================================================================== -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -/** - * A property of a font that describes its general appearance. - * - * @since POI 3.17-beta2 - */ -public enum FontFamily { - /** - * The default font is specified, which is implementation-dependent. - */ - FF_DONTCARE (0x00), - /** - * Fonts with variable stroke widths, which are proportional to the actual widths of - * the glyphs, and which have serifs. "MS Serif" is an example. - */ - FF_ROMAN (0x01), - /** - * Fonts with variable stroke widths, which are proportional to the actual widths of the - * glyphs, and which do not have serifs. "MS Sans Serif" is an example. - */ - FF_SWISS (0x02), - /** - * Fonts with constant stroke width, with or without serifs. Fixed-width fonts are - * usually modern. "Pica", "Elite", and "Courier New" are examples. - */ - FF_MODERN (0x03), - /** - * Fonts designed to look like handwriting. "Script" and "Cursive" are examples. - */ - FF_SCRIPT (0x04), - /** - * Novelty fonts. "Old English" is an example. - */ - FF_DECORATIVE (0x05); - - private int nativeId; - private FontFamily(int nativeId) { - this.nativeId = nativeId; - } - - public int getFlag() { - return nativeId; - } - - public static FontFamily valueOf(int nativeId) { - for (FontFamily ff : values()) { - if (ff.nativeId == nativeId) { - return ff; - } - } - return null; - } - - /** - * Get FontFamily from combined native id - * - * @param pitchAndFamily The PitchFamily to decode. - * - * @return The resulting FontFamily - */ - public static FontFamily valueOfPitchFamily(byte pitchAndFamily) { - return valueOf(pitchAndFamily >>> 4); - } -} diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontGroup.java b/src/java/org/apache/poi/common/usermodel/fonts/FontGroup.java deleted file mode 100644 index cdbaefe90f..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontGroup.java +++ /dev/null @@ -1,164 +0,0 @@ -/* ==================================================================== -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.NavigableMap; -import java.util.TreeMap; - -/** - * Text runs can contain characters which will be handled (if configured) by a different font, - * because the default font (latin) doesn't contain corresponding glyphs. - * - * @since POI 3.17-beta2 - * - * @see <a href="https://blogs.msdn.microsoft.com/officeinteroperability/2013/04/22/office-open-xml-themes-schemes-and-fonts/">Office Open XML Themes, Schemes, and Fonts</a> - */ -public enum FontGroup { - /** type for latin charset (default) - also used for unicode fonts like MS Arial Unicode */ - LATIN, - /** type for east asian charsets - usually set as fallback for the latin font, e.g. something like MS Gothic or MS Mincho */ - EAST_ASIAN, - /** type for symbol fonts */ - SYMBOL, - /** type for complex scripts - see https://msdn.microsoft.com/en-us/library/windows/desktop/dd317698 */ - COMPLEX_SCRIPT - ; - - - public static class FontGroupRange { - private final FontGroup fontGroup; - private int len = 0; - - FontGroupRange(FontGroup fontGroup) { - this.fontGroup = fontGroup; - } - - public int getLength() { - return len; - } - - public FontGroup getFontGroup( ) { - return fontGroup; - } - - void increaseLength(int len) { - this.len += len; - } - } - - private static class Range { - private final int upper; - private final FontGroup fontGroup; - Range(int upper, FontGroup fontGroup) { - this.upper = upper; - this.fontGroup = fontGroup; - } - - int getUpper() { return upper; } - FontGroup getFontGroup() { return fontGroup; } - } - - private static NavigableMap<Integer,Range> UCS_RANGES; - - static { - UCS_RANGES = new TreeMap<>(); - UCS_RANGES.put(0x0000, new Range(0x007F, LATIN)); - UCS_RANGES.put(0x0080, new Range(0x00A6, LATIN)); - UCS_RANGES.put(0x00A9, new Range(0x00AF, LATIN)); - UCS_RANGES.put(0x00B2, new Range(0x00B3, LATIN)); - UCS_RANGES.put(0x00B5, new Range(0x00D6, LATIN)); - UCS_RANGES.put(0x00D8, new Range(0x00F6, LATIN)); - UCS_RANGES.put(0x00F8, new Range(0x058F, LATIN)); - UCS_RANGES.put(0x0590, new Range(0x074F, COMPLEX_SCRIPT)); - UCS_RANGES.put(0x0780, new Range(0x07BF, COMPLEX_SCRIPT)); - UCS_RANGES.put(0x0900, new Range(0x109F, COMPLEX_SCRIPT)); - UCS_RANGES.put(0x10A0, new Range(0x10FF, LATIN)); - UCS_RANGES.put(0x1200, new Range(0x137F, LATIN)); - UCS_RANGES.put(0x13A0, new Range(0x177F, LATIN)); - UCS_RANGES.put(0x1D00, new Range(0x1D7F, LATIN)); - UCS_RANGES.put(0x1E00, new Range(0x1FFF, LATIN)); - UCS_RANGES.put(0x1780, new Range(0x18AF, COMPLEX_SCRIPT)); - UCS_RANGES.put(0x2000, new Range(0x200B, LATIN)); - UCS_RANGES.put(0x200C, new Range(0x200F, COMPLEX_SCRIPT)); - // For the quote characters in the range U+2018 - U+201E, use the East Asian font - // if the text has one of the following language identifiers: - // ii-CN, ja-JP, ko-KR, zh-CN,zh-HK, zh-MO, zh-SG, zh-TW - UCS_RANGES.put(0x2010, new Range(0x2029, LATIN)); - UCS_RANGES.put(0x202A, new Range(0x202F, COMPLEX_SCRIPT)); - UCS_RANGES.put(0x2030, new Range(0x2046, LATIN)); - UCS_RANGES.put(0x204A, new Range(0x245F, LATIN)); - UCS_RANGES.put(0x2670, new Range(0x2671, COMPLEX_SCRIPT)); - UCS_RANGES.put(0x27C0, new Range(0x2BFF, LATIN)); - UCS_RANGES.put(0x3099, new Range(0x309A, EAST_ASIAN)); - UCS_RANGES.put(0xD835, new Range(0xD835, LATIN)); - UCS_RANGES.put(0xF000, new Range(0xF0FF, SYMBOL)); - UCS_RANGES.put(0xFB00, new Range(0xFB17, LATIN)); - UCS_RANGES.put(0xFB1D, new Range(0xFB4F, COMPLEX_SCRIPT)); - UCS_RANGES.put(0xFE50, new Range(0xFE6F, LATIN)); - // All others EAST_ASIAN - } - - - /** - * Try to guess the font group based on the codepoint - * - * @param runText the text which font groups are to be analyzed - * @return the FontGroup - */ - public static List<FontGroupRange> getFontGroupRanges(final String runText) { - final List<FontGroupRange> ttrList = new ArrayList<>(); - if (runText == null || runText.isEmpty()) { - return ttrList; - } - FontGroupRange ttrLast = null; - final int rlen = runText.length(); - for(int cp, i = 0, charCount; i < rlen; i += charCount) { - cp = runText.codePointAt(i); - charCount = Character.charCount(cp); - - // don't switch the font group for a few default characters supposedly available in all fonts - final FontGroup tt; - if (ttrLast != null && " \n\r".indexOf(cp) > -1) { - tt = ttrLast.fontGroup; - } else { - tt = lookup(cp); - } - - if (ttrLast == null || ttrLast.fontGroup != tt) { - ttrLast = new FontGroupRange(tt); - ttrList.add(ttrLast); - } - ttrLast.increaseLength(charCount); - } - return ttrList; - } - - public static FontGroup getFontGroupFirst(String runText) { - return (runText == null || runText.isEmpty()) ? LATIN : lookup(runText.codePointAt(0)); - } - - private static FontGroup lookup(int codepoint) { - // Do a lookup for a match in UCS_RANGES - Map.Entry<Integer, Range> entry = UCS_RANGES.floorEntry(codepoint); - Range range = (entry != null) ? entry.getValue() : null; - return (range != null && codepoint <= range.getUpper()) ? range.getFontGroup() : EAST_ASIAN; - } -}
\ No newline at end of file diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontHeader.java b/src/java/org/apache/poi/common/usermodel/fonts/FontHeader.java deleted file mode 100644 index 2589b16f17..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontHeader.java +++ /dev/null @@ -1,376 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -import static org.apache.poi.util.GenericRecordUtil.getBitsAsString; -import static org.apache.poi.util.GenericRecordUtil.safeEnum; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Supplier; - -import org.apache.poi.common.usermodel.GenericRecord; -import org.apache.poi.util.IOUtils; -import org.apache.poi.util.LittleEndianByteArrayInputStream; -import org.apache.poi.util.LittleEndianInput; -import org.apache.poi.util.LittleEndianInputStream; - - -/** - * The header data of an EOT font.<p> - * - * Currently only version 1 fields are read to identify a stream to be embedded. - * - * @see <a href="http://www.w3.org/Submission/EOT">Embedded OpenType (EOT) File Format</a> - */ -@SuppressWarnings({"FieldCanBeLocal", "unused", "Duplicates", "WeakerAccess"}) -public class FontHeader implements FontInfo, GenericRecord { - - public enum PanoseFamily { - ANY, NO_FIT, TEXT_DISPLAY, SCRIPT, DECORATIVE, PICTORIAL - } - - public enum PanoseSerif { - ANY, NO_FIT, COVE, OBTUSE_COVE, SQUARE_COVE, OBTUSE_SQUARE_COVE, SQUARE, THIN, BONE, - EXAGGERATED, TRIANGLE, NORMAL_SANS, OBTUSE_SANS, PERP_SANS, FLARED, ROUNDED - } - - public enum PanoseWeight { - ANY, NO_FIT, VERY_LIGHT, LIGHT, THIN, BOOK, MEDIUM, DEMI, BOLD, HEAVY, BLACK, NORD - } - - public enum PanoseProportion { - ANY, NO_FIT, OLD_STYLE, MODERN, EVEN_WIDTH, EXPANDED, CONDENSED, VERY_EXPANDED, VERY_CONDENSED, MONOSPACED - } - - public enum PanoseContrast { - ANY, NO_FIT, NONE, VERY_LOW, LOW, MEDIUM_LOW, MEDIUM, MEDIUM_HIGH, HIGH, VERY_HIGH - } - - public enum PanoseStroke { - ANY, NO_FIT, GRADUAL_DIAG, GRADUAL_TRAN, GRADUAL_VERT, GRADUAL_HORZ, RAPID_VERT, RAPID_HORZ, INSTANT_VERT - } - - public enum PanoseArmStyle { - ANY, NO_FIT, STRAIGHT_ARMS_HORZ, STRAIGHT_ARMS_WEDGE, STRAIGHT_ARMS_VERT, STRAIGHT_ARMS_SINGLE_SERIF, - STRAIGHT_ARMS_DOUBLE_SERIF, BENT_ARMS_HORZ, BENT_ARMS_WEDGE, BENT_ARMS_VERT, BENT_ARMS_SINGLE_SERIF, - BENT_ARMS_DOUBLE_SERIF, - } - - public enum PanoseLetterForm { - ANY, NO_FIT, NORMAL_CONTACT, NORMAL_WEIGHTED, NORMAL_BOXED, NORMAL_FLATTENED, NORMAL_ROUNDED, - NORMAL_OFF_CENTER, NORMAL_SQUARE, OBLIQUE_CONTACT, OBLIQUE_WEIGHTED, OBLIQUE_BOXED, OBLIQUE_FLATTENED, - OBLIQUE_ROUNDED, OBLIQUE_OFF_CENTER, OBLIQUE_SQUARE - } - - public enum PanoseMidLine { - ANY, NO_FIT, STANDARD_TRIMMED, STANDARD_POINTED, STANDARD_SERIFED, HIGH_TRIMMED, HIGH_POINTED, HIGH_SERIFED, - CONSTANT_TRIMMED, CONSTANT_POINTED, CONSTANT_SERIFED, LOW_TRIMMED, LOW_POINTED, LOW_SERIFED - } - - public enum PanoseXHeight { - ANY, NO_FIT, CONSTANT_SMALL, CONSTANT_STD, CONSTANT_LARGE, DUCKING_SMALL, DUCKING_STD, DUCKING_LARGE - } - - private static final int[] FLAGS_MASKS = { - 0x00000001, 0x00000004, 0x00000010, 0x00000020, 0x00000040, 0x00000080, 0x10000000 - }; - - private static final String[] FLAGS_NAMES = { - "SUBSET", "TTCOMPRESSED", "FAILIFVARIATIONSIMULATED", "EMBEDEUDC", "VALIDATIONTESTS", "WEBOBJECT", "XORENCRYPTDATA" - }; - - private static final int[] FSTYPE_MASKS = { - 0x0000, 0x0002, 0x0004, 0x0008, 0x0100, 0x0200 - }; - - private static final String[] FSTYPE_NAMES = { - "INSTALLABLE_EMBEDDING", - "RESTRICTED_LICENSE_EMBEDDING", - "PREVIEW_PRINT_EMBEDDING", - "EDITABLE_EMBEDDING", - "NO_SUBSETTING", - "BITMAP_EMBEDDING_ONLY" - }; - - /** - * Fonts with a font weight of 400 are regarded as regular weighted. - * Higher font weights (up to 1000) are bold - lower weights are thin. - */ - public static final int REGULAR_WEIGHT = 400; - - private int eotSize; - private int fontDataSize; - private int version; - private int flags; - private final byte[] panose = new byte[10]; - private byte charset; - private byte italic; - private int weight; - private int fsType; - private int magic; - private int unicodeRange1; - private int unicodeRange2; - private int unicodeRange3; - private int unicodeRange4; - private int codePageRange1; - private int codePageRange2; - private int checkSumAdjustment; - private String familyName; - private String styleName; - private String versionName; - private String fullName; - - public void init(byte[] source, int offset, int length) { - init(new LittleEndianByteArrayInputStream(source, offset, length)); - } - - public void init(LittleEndianInput leis) { - eotSize = leis.readInt(); - fontDataSize = leis.readInt(); - version = leis.readInt(); - if (version != 0x00010000 && version != 0x00020001 && version != 0x00020002) { - throw new RuntimeException("not a EOT font data stream"); - } - flags = leis.readInt(); - leis.readFully(panose); - charset = leis.readByte(); - italic = leis.readByte(); - weight = leis.readInt(); - fsType = leis.readUShort(); - magic = leis.readUShort(); - if (magic != 0x504C) { - throw new RuntimeException("not a EOT font data stream"); - } - unicodeRange1 = leis.readInt(); - unicodeRange2 = leis.readInt(); - unicodeRange3 = leis.readInt(); - unicodeRange4 = leis.readInt(); - codePageRange1 = leis.readInt(); - codePageRange2 = leis.readInt(); - checkSumAdjustment = leis.readInt(); - int reserved1 = leis.readInt(); - int reserved2 = leis.readInt(); - int reserved3 = leis.readInt(); - int reserved4 = leis.readInt(); - familyName = readName(leis); - styleName = readName(leis); - versionName = readName(leis); - fullName = readName(leis); - - } - - public InputStream bufferInit(InputStream fontStream) throws IOException { - LittleEndianInputStream is = new LittleEndianInputStream(fontStream); - is.mark(1000); - init(is); - is.reset(); - return is; - } - - private String readName(LittleEndianInput leis) { - // padding - leis.readShort(); - int nameSize = leis.readUShort(); - byte[] nameBuf = IOUtils.safelyAllocate(nameSize, 1000); - leis.readFully(nameBuf); - // may be 0-terminated, just trim it away - return new String(nameBuf, 0, nameSize, StandardCharsets.UTF_16LE).trim(); - } - - public boolean isItalic() { - return italic != 0; - } - - public int getWeight() { - return weight; - } - - public boolean isBold() { - return getWeight() > REGULAR_WEIGHT; - } - - public byte getCharsetByte() { - return charset; - } - - public FontCharset getCharset() { - return FontCharset.valueOf(getCharsetByte()); - } - - public FontPitch getPitch() { - switch (getPanoseFamily()) { - default: - case ANY: - case NO_FIT: - return FontPitch.VARIABLE; - - // Latin Text - case TEXT_DISPLAY: - // Latin Decorative - case DECORATIVE: - return (getPanoseProportion() == PanoseProportion.MONOSPACED) ? FontPitch.FIXED : FontPitch.VARIABLE; - - // Latin Hand Written - case SCRIPT: - // Latin Symbol - case PICTORIAL: - return (getPanoseProportion() == PanoseProportion.MODERN) ? FontPitch.FIXED : FontPitch.VARIABLE; - } - - } - - public FontFamily getFamily() { - switch (getPanoseFamily()) { - case ANY: - case NO_FIT: - return FontFamily.FF_DONTCARE; - // Latin Text - case TEXT_DISPLAY: - switch (getPanoseSerif()) { - case TRIANGLE: - case NORMAL_SANS: - case OBTUSE_SANS: - case PERP_SANS: - case FLARED: - case ROUNDED: - return FontFamily.FF_SWISS; - default: - return FontFamily.FF_ROMAN; - } - // Latin Hand Written - case SCRIPT: - return FontFamily.FF_SCRIPT; - // Latin Decorative - default: - case DECORATIVE: - return FontFamily.FF_DECORATIVE; - // Latin Symbol - case PICTORIAL: - return FontFamily.FF_MODERN; - } - } - - public String getFamilyName() { - return familyName; - } - - public String getStyleName() { - return styleName; - } - - public String getVersionName() { - return versionName; - } - - public String getFullName() { - return fullName; - } - - public byte[] getPanose() { - return panose; - } - - @Override - public String getTypeface() { - return getFamilyName(); - } - - public int getFlags() { - return flags; - } - - @Override - public Map<String, Supplier<?>> getGenericProperties() { - final Map<String,Supplier<?>> m = new LinkedHashMap<>(); - m.put("eotSize", () -> eotSize); - m.put("fontDataSize", () -> fontDataSize); - m.put("version", () -> version); - m.put("flags", getBitsAsString(this::getFlags, FLAGS_MASKS, FLAGS_NAMES)); - m.put("panose.familyType", this::getPanoseFamily); - m.put("panose.serifType", this::getPanoseSerif); - m.put("panose.weight", this::getPanoseWeight); - m.put("panose.proportion", this::getPanoseProportion); - m.put("panose.contrast", this::getPanoseContrast); - m.put("panose.stroke", this::getPanoseStroke); - m.put("panose.armStyle", this::getPanoseArmStyle); - m.put("panose.letterForm", this::getPanoseLetterForm); - m.put("panose.midLine", this::getPanoseMidLine); - m.put("panose.xHeight", this::getPanoseXHeight); - m.put("charset", this::getCharset); - m.put("italic", this::isItalic); - m.put("weight", this::getWeight); - m.put("fsType", getBitsAsString(() -> fsType, FSTYPE_MASKS, FSTYPE_NAMES)); - m.put("unicodeRange1", () -> unicodeRange1); - m.put("unicodeRange2", () -> unicodeRange2); - m.put("unicodeRange3", () -> unicodeRange3); - m.put("unicodeRange4", () -> unicodeRange4); - m.put("codePageRange1", () -> codePageRange1); - m.put("codePageRange2", () -> codePageRange2); - m.put("checkSumAdjustment", () -> checkSumAdjustment); - m.put("familyName", this::getFamilyName); - m.put("styleName", this::getStyleName); - m.put("versionName", this::getVersionName); - m.put("fullName", this::getFullName); - return Collections.unmodifiableMap(m); - } - - public PanoseFamily getPanoseFamily() { - return safeEnum(PanoseFamily.values(), () -> panose[0]).get(); - } - - public PanoseSerif getPanoseSerif() { - return safeEnum(PanoseSerif.values(), () -> panose[1]).get(); - } - - public PanoseWeight getPanoseWeight() { - return safeEnum(PanoseWeight.values(), () -> panose[2]).get(); - } - - public PanoseProportion getPanoseProportion() { - return safeEnum(PanoseProportion.values(), () -> panose[3]).get(); - } - - public PanoseContrast getPanoseContrast() { - return safeEnum(PanoseContrast.values(), () -> panose[4]).get(); - } - - public PanoseStroke getPanoseStroke() { - return safeEnum(PanoseStroke.values(), () -> panose[5]).get(); - } - - public PanoseArmStyle getPanoseArmStyle() { - return safeEnum(PanoseArmStyle.values(), () -> panose[6]).get(); - } - - public PanoseLetterForm getPanoseLetterForm() { - return safeEnum(PanoseLetterForm.values(), () -> panose[7]).get(); - } - - public PanoseMidLine getPanoseMidLine() { - return safeEnum(PanoseMidLine.values(), () -> panose[8]).get(); - } - - public PanoseXHeight getPanoseXHeight() { - return safeEnum(PanoseXHeight.values(), () -> panose[9]).get(); - } -} diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontInfo.java b/src/java/org/apache/poi/common/usermodel/fonts/FontInfo.java deleted file mode 100644 index b47b02e53b..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontInfo.java +++ /dev/null @@ -1,152 +0,0 @@ -/* ==================================================================== -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -import java.util.Collections; -import java.util.List; - -import org.apache.poi.util.Beta; - -/** - * A FontInfo object holds information about a font configuration. - * It is roughly an equivalent to the LOGFONT structure in Windows GDI.<p> - * - * If an implementation doesn't provide a property, the getter will return {@code null} - - * if the value is unset, a default value will be returned.<p> - * - * Setting a unsupported property results in an {@link UnsupportedOperationException}. - * - * @since POI 3.17-beta2 - * - * @see <a href="https://msdn.microsoft.com/en-us/library/dd145037.aspx">LOGFONT structure</a> - */ -@SuppressWarnings("unused") -public interface FontInfo { - - /** - * Get the index within the collection of Font objects - * @return unique index number of the underlying record this Font represents - * (probably you don't care unless you're comparing which one is which) - */ - default Integer getIndex() { - return null; - } - - /** - * Sets the index within the collection of Font objects - * - * @param index the index within the collection of Font objects - * - * @throws UnsupportedOperationException if unsupported - */ - default void setIndex(int index) { - throw new UnsupportedOperationException("FontInfo is read-only."); - } - - - /** - * @return the full name of the font, i.e. font family + type face - */ - String getTypeface(); - - /** - * Sets the font name - * - * @param typeface the full name of the font, when {@code null} removes the font definition - - * removal is implementation specific - */ - default void setTypeface(String typeface) { - throw new UnsupportedOperationException("FontInfo is read-only."); - } - - /** - * @return the font charset - */ - default FontCharset getCharset() { - return FontCharset.ANSI; - } - - /** - * Sets the charset - * - * @param charset the charset - */ - default void setCharset(FontCharset charset) { - throw new UnsupportedOperationException("FontInfo is read-only."); - } - - /** - * @return the family class - */ - default FontFamily getFamily() { - return FontFamily.FF_DONTCARE; - } - - /** - * Sets the font family class - * - * @param family the font family class - */ - default void setFamily(FontFamily family) { - throw new UnsupportedOperationException("FontInfo is read-only."); - } - - /** - * @return the font pitch or {@code null} if unsupported - */ - default FontPitch getPitch() { - return null; - } - - /** - * Set the font pitch - * - * @param pitch the font pitch - * - * @throws UnsupportedOperationException if unsupported - */ - default void setPitch(FontPitch pitch) { - throw new UnsupportedOperationException("FontInfo is read-only."); - } - - /** - * @return panose info in binary form or {@code null} if unknown - */ - default byte[] getPanose() { - return null; - } - - /** - * Set the panose in binary form - * @param panose the panose bytes - */ - default void setPanose(byte[] panose) { - throw new UnsupportedOperationException("FontInfo is read-only."); - } - - - /** - * If font facets are embedded in the document, return the list of embedded facets. - * The font embedding is experimental, therefore the API can change. - * @return the list of embedded EOT font data - */ - @Beta - default List<? extends FontFacet> getFacets() { - return Collections.emptyList(); - } -}
\ No newline at end of file diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontPitch.java b/src/java/org/apache/poi/common/usermodel/fonts/FontPitch.java deleted file mode 100644 index 5d1d48e63e..0000000000 --- a/src/java/org/apache/poi/common/usermodel/fonts/FontPitch.java +++ /dev/null @@ -1,82 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.common.usermodel.fonts; - -/** - * A property of a font that describes the pitch, of the characters. - * - * @since POI 3.17-beta2 - */ -public enum FontPitch { - /** - * The default pitch, which is implementation-dependent. - */ - DEFAULT (0x00), - /** - * A fixed pitch, which means that all the characters in the font occupy the same - * width when output in a string. - */ - FIXED (0x01), - /** - * A variable pitch, which means that the characters in the font occupy widths - * that are proportional to the actual widths of the glyphs when output in a string. For example, - * the "i" and space characters usually have much smaller widths than a "W" or "O" character. - */ - VARIABLE (0x02); - - private int nativeId; - FontPitch(int nativeId) { - this.nativeId = nativeId; - } - - public int getNativeId() { - return nativeId; - } - - public static FontPitch valueOf(int flag) { - for (FontPitch fp : values()) { - if (fp.nativeId == flag) return fp; - } - return null; - } - - /** - * Combine pitch and family to native id - * - * @see <a href="https://msdn.microsoft.com/en-us/library/dd145037.aspx">LOGFONT structure</a> - * - * @param pitch The pitch-value, cannot be null - * @param family The family-value, cannot be null - * - * @return The resulting combined byte-value with pitch and family encoded into one byte - */ - public static byte getNativeId(FontPitch pitch, FontFamily family) { - return (byte)(pitch.getNativeId() | (family.getFlag() << 4)); - } - - /** - * Get FontPitch from native id - * - * @param pitchAndFamily The combined byte value for pitch and family - * - * @return The resulting FontPitch enumeration value - */ - public static FontPitch valueOfPitchFamily(byte pitchAndFamily) { - return valueOf(pitchAndFamily & 0x3); - } -} |