You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/10/12 17:55:50 UTC
svn commit: r1868358 - in /poi: site/src/documentation/content/xdocs/
trunk/src/java/org/apache/poi/hpsf/
trunk/src/scratchpad/src/org/apache/poi/hslf/record/
trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/
Author: kiwiwings
Date: Sat Oct 12 17:55:50 2019
New Revision: 1868358
URL: http://svn.apache.org/viewvc?rev=1868358&view=rev
Log:
#63818 - Allow multiple charsets for same font typeface
Modified:
poi/site/src/documentation/content/xdocs/changes.xml
poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java
Modified: poi/site/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/changes.xml?rev=1868358&r1=1868357&r2=1868358&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/changes.xml (original)
+++ poi/site/src/documentation/content/xdocs/changes.xml Sat Oct 12 17:55:50 2019
@@ -95,6 +95,7 @@
<summary-item>Upgrade to Commons-Compress 1.19</summary-item>
</summary>
<actions>
+ <action dev="PD" type="fix" fixes-bug="63818" context="HSLF">Allow multiple charsets for same font typeface</action>
<action dev="PD" type="fix" fixes-bug="63768" context="XSSF">XSSFExportToXml adjust settings on SchemaFactory</action>
<action dev="PD" type="fix" fixes-bug="63541" context="XSLF">NullPointerException from XSLFSimpleShape.getAnchor for empty xfrm tags</action>
<action dev="PD" type="add" fixes-bug="63745" context="POI_Overall">Add traversing and debugging interface</action>
Modified: poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java?rev=1868358&r1=1868357&r2=1868358&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java Sat Oct 12 17:55:50 2019
@@ -84,7 +84,9 @@ public enum ClassIDPredefined {
/** AcroExch.Document */
PDF ("{B801CA65-A1FC-11D0-85AD-444553540000}", ".pdf", "application/pdf"),
/** Plain Text Persistent Handler **/
- TXT_ONLY ("{5e941d80-bf96-11cd-b579-08002b30bfeb}", ".txt", "text/plain")
+ TXT_ONLY ("{5e941d80-bf96-11cd-b579-08002b30bfeb}", ".txt", "text/plain"),
+ /** Microsoft Paint **/
+ PAINT ("{0003000A-0000-0000-C000-000000000046}", null, null)
;
private static final Map<String,ClassIDPredefined> LOOKUP = new HashMap<>();
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java?rev=1868358&r1=1868357&r2=1868358&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java Sat Oct 12 17:55:50 2019
@@ -24,8 +24,10 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.Predicate;
import java.util.function.Supplier;
+import org.apache.poi.common.usermodel.fonts.FontCharset;
import org.apache.poi.common.usermodel.fonts.FontHeader;
import org.apache.poi.common.usermodel.fonts.FontInfo;
import org.apache.poi.common.usermodel.fonts.FontPitch;
@@ -41,7 +43,7 @@ import org.apache.poi.util.POILogger;
@SuppressWarnings("WeakerAccess")
public final class FontCollection extends RecordContainer {
- private final Map<String,HSLFFontInfo> fonts = new LinkedHashMap<>();
+ private final Map<Integer,HSLFFontInfo> fonts = new LinkedHashMap<>();
private byte[] _header;
/* package */ FontCollection(byte[] source, int start, int len) {
@@ -53,7 +55,7 @@ public final class FontCollection extend
for (Record r : _children){
if(r instanceof FontEntityAtom) {
HSLFFontInfo fi = new HSLFFontInfo((FontEntityAtom) r);
- fonts.put(fi.getTypeface(), fi);
+ fonts.put(fi.getIndex(), fi);
} else if (r instanceof FontEmbeddedData) {
FontEmbeddedData fed = (FontEmbeddedData)r;
FontHeader fontHeader = fed.getFontHeader();
@@ -93,14 +95,14 @@ public final class FontCollection extend
* @return the register HSLFFontInfo object
*/
public HSLFFontInfo addFont(FontInfo fontInfo) {
- HSLFFontInfo fi = getFontInfo(fontInfo.getTypeface());
+ HSLFFontInfo fi = getFontInfo(fontInfo.getTypeface(), fontInfo.getCharset());
if (fi != null) {
return fi;
}
fi = new HSLFFontInfo(fontInfo);
fi.setIndex(fonts.size());
- fonts.put(fi.getTypeface(), fi);
+ fonts.put(fi.getIndex(), fi);
FontEntityAtom fnt = fi.createRecord();
@@ -172,7 +174,23 @@ public final class FontCollection extend
* @return the HSLFFontInfo for the given name or {@code null} if not found
*/
public HSLFFontInfo getFontInfo(String typeface) {
- return fonts.get(typeface);
+ return getFontInfo(typeface, null);
+ }
+
+ /**
+ * Lookup a FontInfo object by its typeface
+ *
+ * @param typeface the full font name
+ * @param charset the charset
+ *
+ * @return the HSLFFontInfo for the given name or {@code null} if not found
+ */
+ public HSLFFontInfo getFontInfo(String typeface, FontCharset charset) {
+ return fonts.values().stream().filter(findFont(typeface, charset)).findFirst().orElse(null);
+ }
+
+ private static Predicate<HSLFFontInfo> findFont(String typeface, FontCharset charset) {
+ return (fi) -> typeface.equals(fi.getTypeface()) && (charset == null || charset.equals(fi.getCharset()));
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java?rev=1868358&r1=1868357&r2=1868358&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java Sat Oct 12 17:55:50 2019
@@ -89,38 +89,50 @@ public final class HSLFSlideMaster exten
*/
@Override
public TextPropCollection getPropCollection(final int txtype, final int level, final String name, final boolean isCharacter) {
- if (txtype < _txmaster.length) {
- final TxMasterStyleAtom t = _txmaster[txtype];
- final List<TextPropCollection> styles = isCharacter ? t.getCharacterStyles() : t.getParagraphStyles();
- // TODO: what is the reaction for readOnly=false and styles.isEmpty()?
- final int minLevel = Math.min(level, styles.size()-1);
- if ("*".equals(name)) {
- return styles.get(minLevel);
- }
-
- for (int i=minLevel; i >= 0; i--) {
- final TextPropCollection col = styles.get(i);
- final TextProp tp = col.findByName(name);
- if (tp != null) {
- return col;
- }
- }
+ TextPropCollection tpc = getPropHelper(txtype, level, name, isCharacter);
+ if (tpc != null) {
+ return tpc;
}
- switch (TextPlaceholder.fromNativeId(txtype)) {
+ TextPlaceholder tp = TextPlaceholder.fromNativeId(txtype);
+ switch (tp == null ? TextPlaceholder.BODY : tp) {
case BODY:
case CENTER_BODY:
case HALF_BODY:
case QUARTER_BODY:
- return getPropCollection(TextPlaceholder.BODY.nativeId, level, name, isCharacter);
+ return getPropHelper(TextPlaceholder.BODY.nativeId, level, name, isCharacter);
case TITLE:
case CENTER_TITLE:
- return getPropCollection(TextPlaceholder.TITLE.nativeId, level, name, isCharacter);
+ return getPropHelper(TextPlaceholder.TITLE.nativeId, level, name, isCharacter);
default:
return null;
}
}
+ private TextPropCollection getPropHelper(final int txtype, final int level, final String name, final boolean isCharacter) {
+ if (txtype >= _txmaster.length) {
+ return null;
+ }
+ final TxMasterStyleAtom t = _txmaster[txtype];
+ final List<TextPropCollection> styles = isCharacter ? t.getCharacterStyles() : t.getParagraphStyles();
+ // TODO: what is the reaction for readOnly=false and styles.isEmpty()?
+ final int minLevel = Math.min(level, styles.size()-1);
+ if ("*".equals(name)) {
+ return styles.get(minLevel);
+ }
+
+ for (int i=minLevel; i >= 0; i--) {
+ final TextPropCollection col = styles.get(i);
+ final TextProp tp = col.findByName(name);
+ if (tp != null) {
+ return col;
+ }
+ }
+
+ return null;
+ }
+
+
/**
* Assign SlideShow for this slide master.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org