Changeset 211


Ignore:
Timestamp:
03/21/08 01:12:13 (4 years ago)
Author:
jharrop
Message:

Support for reading a .TTC - necessary to handle Microsoft Cambria font.

Location:
trunk/docx4j
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/fonts/Substituter.java

    r210 r211  
    6464        /* 
    6565         * TODO 
    66          * - handle Cambria & Cambria Math TTC 
     66         * - handle Cambria & Cambria Math TTC; currently org.apache.fop.fonts.autodetect.FontFileFinder  
     67         *   says "TODO Add *.ttc when support for it has been added to the auto-detection mech."; we 
     68         *   need that first. 
     69         *    
    6770         * - Re-enable font cache 
    6871         *  
     
    195198        FontFileFinder fontFileFinder = new FontFileFinder(); 
    196199         
    197         // Automagically finds a list of font files on local system 
    198         // based on os.name 
    199         List fontFileList = fontFileFinder.find();                 
    200         for (Iterator iter = fontFileList.iterator(); iter.hasNext();) { 
    201             URL fontUrl = (URL)iter.next(); 
    202             // parse font to ascertain font info 
    203             FontInfoFinder finder = new FontInfoFinder(); 
    204             setupPhysicalFont(fontResolver, fontUrl, finder); 
    205         } 
     200//        // Automagically finds a list of font files on local system 
     201//        // based on os.name 
     202//        List fontFileList = fontFileFinder.find();                 
     203//        for (Iterator iter = fontFileList.iterator(); iter.hasNext();) { 
     204//            URL fontUrl = (URL)iter.next(); 
     205//            // parse font to ascertain font info 
     206//            FontInfoFinder finder = new FontInfoFinder(); 
     207//            setupPhysicalFont(fontResolver, fontUrl, finder); 
     208//        } 
    206209 
    207210        // Add fonts from our Temporary Embedded Fonts dir 
    208         fontFileList = fontFileFinder.find( ObfuscatedFontPart.getTemporaryEmbeddedFontsDir() ); 
     211        List fontFileList = fontFileFinder.find( ObfuscatedFontPart.getTemporaryEmbeddedFontsDir() ); 
    209212        for (Iterator iter = fontFileList.iterator(); iter.hasNext();) { 
    210213            URL fontUrl = (URL)iter.next(); 
     
    225228         * @param fontResolver 
    226229         * @param fontUrl 
    227          * @param finder 
     230         * @param fontInfoFinder 
    228231         */ 
    229232        public static void setupPhysicalFont(FontResolver fontResolver, 
    230                         URL fontUrl, FontInfoFinder finder) { 
    231                 EmbedFontInfo fontInfo = finder.find(fontUrl, fontResolver, fontCache); 
    232                  
    233                  
    234                 if (fontInfo == null) { 
    235                         return; 
    236                 } 
    237                  if (!fontInfo.isEmbeddable() ) {                                        
    238 //                      log.info(tokens[x] + " is not embeddable; skipping."); 
    239                           
    240                                 // NB isEmbeddable() only exists in our patched FOP 
    241                          
    242                                 /* 
    243                                  * No point looking at this font, since if we tried to use it, 
    244                                  * later, we'd get: 
    245                                  *   
    246                                  * com.lowagie.text.DocumentException: file:/usr/share/fonts/truetype/ttf-tamil-fonts/lohit_ta.ttf cannot be embedded due to licensing restrictions. 
    247                                         at com.lowagie.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:364) 
    248                                         at com.lowagie.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:335) 
    249                                         at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:399) 
    250                                         at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:345) 
    251                                         at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:164) 
    252                                          
    253                                         will be thrown if os_2.fsType == 2 
    254                                          
    255                                  */ 
    256 //                      log.info(physicalFontKey + " is not embeddable; skipping."); 
    257                           
    258                          return; 
    259                  } 
    260                          
    261                 PhysicalFont pf;  
    262                  
    263                 for (Iterator iterIn = fontInfo.getFontTriplets().iterator() ; iterIn.hasNext();) { 
    264                         FontTriplet triplet = (FontTriplet)iterIn.next();  
    265                         // There is one triplet for each of the font family names 
    266                         // this font has, and we create a PhysicalFont object  
    267                         // for each of them.  For our purposes though, each of 
    268                         // these physical font objects contains the same info 
    269                  
    270                 String lower = fontInfo.getEmbedFile().toLowerCase(); 
    271                                          
    272                 pf = null; 
    273                 // xhtmlrenderer's org.xhtmlrenderer.pdf.ITextFontResolver.addFont 
    274                 // can handle 
    275                 // .otf, .ttf, .ttc, .pfb 
    276                 if (lower.endsWith(".otf") || lower.endsWith(".ttf")) { 
    277                         pf = new PhysicalFont(fontInfo); 
    278                 } else if (lower.endsWith(".pfb") ) { 
    279                         // See whether we have everything org.xhtmlrenderer.pdf.ITextFontResolver.addFont 
    280                         // will need - for a .pfb file, it needs a corresponding .afm or .pfm 
    281                                 String afm = FontUtils.pathFromURL(lower); 
    282                                 afm = afm.substring(0, afm.length()-4 ) + ".afm";  // drop the 'file:' 
    283                                 //log.debug("Looking for: " + afm);                                      
    284                                 File f = new File(afm); 
    285                         if (f.exists()) {                                
     233                        URL fontUrl, FontInfoFinder fontInfoFinder) { 
     234                 
     235                List<EmbedFontInfo> embedFontInfoList = fontInfoFinder.find(fontUrl, fontResolver, fontCache);           
     236                 
     237                for ( EmbedFontInfo fontInfo : embedFontInfoList ) { 
     238                         
     239                         
     240                        if (fontInfo == null) { 
     241                                return; 
     242                        } 
     243                         if (!fontInfo.isEmbeddable() ) {                                        
     244        //                      log.info(tokens[x] + " is not embeddable; skipping."); 
     245                                  
     246                                        // NB isEmbeddable() only exists in our patched FOP 
     247                                 
     248                                        /* 
     249                                         * No point looking at this font, since if we tried to use it, 
     250                                         * later, we'd get: 
     251                                         *   
     252                                         * com.lowagie.text.DocumentException: file:/usr/share/fonts/truetype/ttf-tamil-fonts/lohit_ta.ttf cannot be embedded due to licensing restrictions. 
     253                                                at com.lowagie.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:364) 
     254                                                at com.lowagie.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:335) 
     255                                                at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:399) 
     256                                                at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:345) 
     257                                                at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:164) 
     258                                                 
     259                                                will be thrown if os_2.fsType == 2 
     260                                                 
     261                                         */ 
     262        //                      log.info(physicalFontKey + " is not embeddable; skipping."); 
     263                                  
     264                                 return; 
     265                         } 
     266                                 
     267                        PhysicalFont pf;  
     268                         
     269                        for (Iterator iterIn = fontInfo.getFontTriplets().iterator() ; iterIn.hasNext();) { 
     270                                FontTriplet triplet = (FontTriplet)iterIn.next();  
     271                                // There is one triplet for each of the font family names 
     272                                // this font has, and we create a PhysicalFont object  
     273                                // for each of them.  For our purposes though, each of 
     274                                // these physical font objects contains the same info 
     275                         
     276                        String lower = fontInfo.getEmbedFile().toLowerCase(); 
     277                                                 
     278                        pf = null; 
     279                        // xhtmlrenderer's org.xhtmlrenderer.pdf.ITextFontResolver.addFont 
     280                        // can handle 
     281                        // .otf, .ttf, .ttc, .pfb 
     282                        if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.endsWith(".ttc") ) { 
    286283                                pf = new PhysicalFont(fontInfo); 
    287                         } else { 
    288                                 // Should we be doing afm first, or pfm? 
    289                                         String pfm = FontUtils.pathFromURL(lower); 
    290                                         pfm = pfm.substring(0, pfm.length()-4 ) + ".pfm";  // drop the 'file:' 
    291                                         //log.debug("Looking for: " + pfm); 
    292                                         f = new File(pfm); 
     284                        } else if (lower.endsWith(".pfb") ) { 
     285                                // See whether we have everything org.xhtmlrenderer.pdf.ITextFontResolver.addFont 
     286                                // will need - for a .pfb file, it needs a corresponding .afm or .pfm 
     287                                        String afm = FontUtils.pathFromURL(lower); 
     288                                        afm = afm.substring(0, afm.length()-4 ) + ".afm";  // drop the 'file:' 
     289                                        //log.debug("Looking for: " + afm);                                      
     290                                        File f = new File(afm); 
    293291                                if (f.exists()) {                                
    294292                                        pf = new PhysicalFont(fontInfo); 
    295293                                } else { 
    296                                         log.warn("Skipping " + triplet.getName() + "; couldn't find .afm or .pfm for : " + fontInfo.getEmbedFile());                                                                                             
     294                                        // Should we be doing afm first, or pfm? 
     295                                                String pfm = FontUtils.pathFromURL(lower); 
     296                                                pfm = pfm.substring(0, pfm.length()-4 ) + ".pfm";  // drop the 'file:' 
     297                                                //log.debug("Looking for: " + pfm); 
     298                                                f = new File(pfm); 
     299                                        if (f.exists()) {                                
     300                                                pf = new PhysicalFont(fontInfo); 
     301                                        } else { 
     302                                                log.warn("Skipping " + triplet.getName() + "; couldn't find .afm or .pfm for : " + fontInfo.getEmbedFile());                                                                                             
     303                                        } 
    297304                                } 
     305                        } else {                         
     306                                log.warn("Skipping " + triplet.getName() + "; unsupported type: " + fontInfo.getEmbedFile());                                            
    298307                        } 
    299                 } else {                         
    300                         log.warn("Skipping " + triplet.getName() + "; unsupported type: " + fontInfo.getEmbedFile());                                            
    301                 } 
    302                  
    303                  
    304                 if (pf!=null) { 
    305                          
    306                         // Add it to the map 
    307                         physicalFontMap.put(pf.getName(), pf); 
    308                         //log.debug("Added " + pf.getName() + " -> " + pf.getEmbeddedFile());                    
    309                          
    310                         // Handle the font family bit - this is critical, since 
    311                         // it is what iText uses 
    312                         String familyName = triplet.getName(); 
    313                         pf.setFamilyName(familyName); 
    314                          
    315                         PhysicalFontFamily pff; 
    316                         if (physicalFontFamiliesMap.get(familyName)==null) { 
    317                                 pff = new PhysicalFontFamily(familyName); 
    318                                 physicalFontFamiliesMap.put(familyName, pff); 
    319                         } else { 
    320                                 pff = physicalFontFamiliesMap.get(familyName); 
    321                         } 
    322                         pff.addFont(pf); 
    323                          
    324                 } 
    325                 }                
     308                         
     309                         
     310                        if (pf!=null) { 
     311                                 
     312                                // Add it to the map 
     313                                physicalFontMap.put(pf.getName(), pf); 
     314                                //log.debug("Added " + pf.getName() + " -> " + pf.getEmbeddedFile());                    
     315                                 
     316                                // Handle the font family bit - this is critical, since 
     317                                // it is what iText uses 
     318                                String familyName = triplet.getName(); 
     319                                pf.setFamilyName(familyName); 
     320                                 
     321                                PhysicalFontFamily pff; 
     322                                if (physicalFontFamiliesMap.get(familyName)==null) { 
     323                                        pff = new PhysicalFontFamily(familyName); 
     324                                        physicalFontFamiliesMap.put(familyName, pff); 
     325                                } else { 
     326                                        pff = physicalFontFamiliesMap.get(familyName); 
     327                                } 
     328                                pff.addFont(pf); 
     329                                 
     330                        } 
     331                        }                
     332                } 
    326333        } 
    327334         
     
    961968        public static void main(String[] args) throws Exception { 
    962969 
    963                 //String inputfilepath = "/home/jharrop/workspace200711/docx4j-001/sample-docs/Word2007-fonts.docx"; 
    964                 String inputfilepath = "C:\\Users\\jharrop\\workspace\\docx4j\\sample-docs\\Word2007-fonts.docx"; 
     970                String inputfilepath = "/home/jharrop/workspace200711/docx4j-001/sample-docs/Word2007-fonts.docx"; 
     971                //String inputfilepath = "C:\\Users\\jharrop\\workspace\\docx4j\\sample-docs\\Word2007-fonts.docx"; 
    965972                //String inputfilepath = "/home/jharrop/workspace200711/docx4j-001/sample-docs/fonts-modesOfApplication.docx"; 
    966973                //String inputfilepath = "/home/jharrop/workspace200711/docx4all/sample-docs/TargetFeatureSet.docx"; //docx4all-fonts.docx"; 
  • trunk/docx4j/src/main/resources/fop-fonts.patch

    r205 r211  
     1Index: /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java 
     2=================================================================== 
     3--- /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java      (revision 631408) 
     4+++ /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java      (working copy) 
     5@@ -78,7 +78,7 @@ 
     6     protected static IOFileFilter getFileFilter() { 
     7         return FileFilterUtils.andFileFilter( 
     8                 FileFilterUtils.fileFileFilter(), 
     9-                new WildcardFileFilter(new String[] {"*.ttf", "*.otf", "*.pfb"}, IOCase.INSENSITIVE) 
     10+                new WildcardFileFilter(new String[] {"*.ttf", "*.otf", "*.pfb", "*.ttc"}, IOCase.INSENSITIVE) 
     11                 //TODO Add *.ttc when support for it has been added to the auto-detection mech. 
     12         ); 
     13     } 
    114Index: /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java 
    215=================================================================== 
    316--- /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java      (revision 631408) 
    417+++ /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java      (working copy) 
    5 @@ -62,11 +62,47 @@ 
     18@@ -20,8 +20,10 @@ 
     19 package org.apache.fop.fonts.autodetect; 
     20  
     21 import java.io.IOException; 
     22+import java.io.InputStream; 
     23 import java.net.URL; 
     24 import java.net.URLConnection; 
     25+import java.util.ArrayList; 
     26 import java.util.Collection; 
     27 import java.util.Iterator; 
     28 import java.util.List; 
     29@@ -41,6 +43,9 @@ 
     30 import org.apache.fop.fonts.FontResolver; 
     31 import org.apache.fop.fonts.FontTriplet; 
     32 import org.apache.fop.fonts.FontUtil; 
     33+import org.apache.fop.fonts.truetype.FontFileReader; 
     34+import org.apache.fop.fonts.truetype.TTFFile; 
     35+import org.apache.fop.fonts.truetype.TTFFontLoader; 
     36  
     37 /** 
     38  * Attempts to determine correct FontInfo 
     39@@ -62,11 +67,47 @@ 
    640             log.trace("Font: " + customFont.getFullName()  
    741                     + ", family: " + customFont.getFamilyNames()  
     
    5286         String fullName = stripQuotes(customFont.getFullName()); 
    5387         String searchName = fullName.toLowerCase(); 
    54 @@ -81,9 +117,10 @@ 
     88@@ -81,9 +122,10 @@ 
    5589         //Full Name usually includes style/weight info so don't use these traits 
    5690         //If we still want to use these traits, we have to make FontInfo.fontLookup() smarter 
     
    66100         Iterator iter = familyNames.iterator(); 
    67101         while (iter.hasNext()) { 
    68 @@ -133,6 +170,9 @@ 
     102@@ -133,6 +175,9 @@ 
    69103         embedUrl = fontUrl.toExternalForm(); 
    70104         EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(), 
     
    76110             fontCache.addFont(fontInfo); 
    77111         } 
     112@@ -145,12 +190,18 @@ 
     113      * @param fontUrl font URL. Assumed to be local. 
     114      * @param resolver font resolver used to resolve font 
     115      * @param fontCache font cache (may be null) 
     116-     * @return newly created embed font info 
     117+     * @return list of newly created embed font info.  Generally, this list 
     118+     *         will have only one entry, unless the fontUrl is a TTC 
     119      */ 
     120-    public EmbedFontInfo find(URL fontUrl, FontResolver resolver, FontCache fontCache) { 
     121+    public List<EmbedFontInfo> find(URL fontUrl, FontResolver resolver, FontCache fontCache) { 
     122+        
     123+       List<EmbedFontInfo> embedFontInfoList = new java.util.ArrayList<EmbedFontInfo>(); 
     124+        
     125         String embedUrl = null; 
     126         embedUrl = fontUrl.toExternalForm(); 
     127          
     128+        System.out.println(embedUrl); 
     129+         
     130         long fileLastModified = -1; 
     131         if (fontCache != null) { 
     132             try { 
     133@@ -170,7 +221,8 @@ 
     134             if (fontCache.containsFont(embedUrl)) { 
     135                 CachedFontInfo fontInfo = fontCache.getFont(embedUrl); 
     136                 if (fontInfo.lastModified() == fileLastModified) { 
     137-                    return fontInfo; 
     138+                       embedFontInfoList.add(fontInfo); 
     139+                    return embedFontInfoList; 
     140                 } else { 
     141                     // out of date cache item 
     142                     fontCache.removeFont(embedUrl); 
     143@@ -184,20 +236,75 @@ 
     144             } 
     145         } 
     146          
     147+         
     148         // try to determine triplet information from font file 
     149         CustomFont customFont = null; 
     150-        try { 
     151-            customFont = FontLoader.loadFont(fontUrl, resolver); 
     152-        } catch (Exception e) { 
     153-            //TODO Too verbose (it's an error but we don't care if some fonts can't be loaded) 
     154-            if (log.isErrorEnabled()) { 
     155-                log.error("Unable to load font file: " + embedUrl + ". Reason: " + e.getMessage()); 
     156+         
     157+        if (fontUrl.toExternalForm().endsWith(".ttc")) { 
     158+                
     159+               // Get a list of the TTC Font names 
     160+               List<String> ttcNames = null; 
     161+               String fontFileURI = fontUrl.toExternalForm().trim(); 
     162+               TTFFontLoader ttfLoader = new TTFFontLoader(fontFileURI, resolver); 
     163+            InputStream in = null;              
     164+            try { 
     165+               in = FontLoader.openFontUri(resolver, fontFileURI); 
     166+                TTFFile ttf = new TTFFile(); 
     167+                FontFileReader reader = new FontFileReader(in); 
     168+                ttcNames = ttf.getTTCnames(reader); 
     169+            } catch (Exception e) { 
     170+               log.error(e); 
     171+            } finally { 
     172+                IOUtils.closeQuietly(in); 
     173             } 
     174-            if (fontCache != null) { 
     175-                fontCache.registerFailedFont(embedUrl, fileLastModified); 
     176+                
     177+               // For each font name ... 
     178+               for (String fontName : ttcNames) { 
     179+ 
     180+                       log.debug("Loading " + fontName); 
     181+                   try { 
     182+                       ttfLoader = new TTFFontLoader(fontFileURI, resolver); 
     183+                       ttfLoader.read(fontName); 
     184+                       customFont = ttfLoader.getFont(); 
     185+                   } catch (Exception e) { 
     186+                       //TODO Too verbose (it's an error but we don't care if some fonts can't be loaded) 
     187+                       //if (log.isErrorEnabled()) { 
     188+                           log.error("Unable to load font file: " + embedUrl + ". Reason: " + e.getMessage()); 
     189+                       //} 
     190+                       if (fontCache != null) { 
     191+                           fontCache.registerFailedFont(embedUrl, fileLastModified); 
     192+                       } 
     193+                       continue; 
     194+                   } 
     195+                   EmbedFontInfo fi = fontInfoFromCustomFont(fontUrl, customFont, fontCache); 
     196+                   if (fi!=null) { 
     197+                       embedFontInfoList.add(fi); 
     198+                   }  
     199+               } 
     200+               return embedFontInfoList; 
     201+        } else { 
     202+               // The normal case 
     203+            try { 
     204+                customFont = FontLoader.loadFont(fontUrl, resolver); 
     205+            } catch (Exception e) { 
     206+                //TODO Too verbose (it's an error but we don't care if some fonts can't be loaded) 
     207+                //if (log.isErrorEnabled()) { 
     208+                    log.error("Unable to load font file: " + embedUrl + ". Reason: " + e.getMessage()); 
     209+                //} 
     210+                if (fontCache != null) { 
     211+                    fontCache.registerFailedFont(embedUrl, fileLastModified); 
     212+                } 
     213+                return null; 
     214             } 
     215-            return null; 
     216+            EmbedFontInfo fi = fontInfoFromCustomFont(fontUrl, customFont, fontCache); 
     217+            if (fi!=null) { 
     218+               embedFontInfoList.add(fi); 
     219+                return embedFontInfoList;               
     220+            } else { 
     221+               return null; 
     222+            }           
     223         } 
     224-        return fontInfoFromCustomFont(fontUrl, customFont, fontCache);      
     225+         
     226+ 
     227     } 
     228 } 
    78229Index: /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/CustomFont.java 
    79230=================================================================== 
     
    150301     /** 
    151302      * Main constructor 
     303Index: /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/FontLoader.java 
     304=================================================================== 
     305--- /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/FontLoader.java     (revision 631408) 
     306+++ /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/FontLoader.java     (working copy) 
     307@@ -121,7 +121,7 @@ 
     308      * @throws IOException In case of an I/O error 
     309      * @throws MalformedURLException If an invalid URL is built 
     310      */ 
     311-    protected static InputStream openFontUri(FontResolver resolver, String uri)  
     312+    public static InputStream openFontUri(FontResolver resolver, String uri)  
     313                     throws IOException, MalformedURLException { 
     314         InputStream in = null; 
     315         if (resolver != null) { 
    152316Index: /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/MultiByteFont.java 
    153317=================================================================== 
     
    192356--- /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/Panose.java (revision 0) 
    193357+++ /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/Panose.java (revision 0) 
    194 @@ -0,0 +1,391 @@ 
     358@@ -0,0 +1,396 @@ 
    195359+/* 
    196360+ * Copyright 2006 The FOray Project. 
     
    451615+               // Already the maximum value - do nothing 
    452616+       } else if (panoseArray[2]<8) { 
    453 +               panoseArray[2]=7; // 8 = bold, but most of the MS ClearType Collection fonts have 7 here. 
     617+               panoseArray[2]=8;  
     618+               // 8 = bold, and even though most of the MS ClearType Collection fonts have 7 here, 
     619+               // experience (Times New Roman) shows it is better to be on the high side, to stop 
     620+               // this Panose array from being equidistant between the normal weight and the 
     621+               // bold weight. 
     622+                
    454623+       } else { 
    455624+               // Do nothing, rather than increase the Weight 
     
    467636+               // Already the maximum value - do nothing 
    468637+       } else if (panoseArray[7]<9) { 
    469 +               panoseArray[7]=9; // Most fonts have 9 or 10 here. 
     638+               panoseArray[7]=10; // Most fonts have 9 or 10 here, so use 10 on the same reasoning as above. 
    470639+       } else { 
    471640+               // Do nothing, rather than increase the Letterform setting  
     
    588757--- /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/truetype/TTFFile.java       (revision 631408) 
    589758+++ /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/truetype/TTFFile.java       (working copy) 
    590 @@ -31,6 +31,7 @@ 
     759@@ -30,7 +30,9 @@ 
     760  
    591761 import org.apache.xmlgraphics.fonts.Glyphs; 
    592762  
     763+import org.apache.fop.fonts.EmbedFontInfo; 
    593764 import org.apache.fop.fonts.FontUtil; 
    594765+import org.apache.fop.fonts.Panose; 
     
    596767 /** 
    597768  * Reads a TrueType file or a TrueType Collection. 
    598 @@ -48,9 +49,12 @@ 
     769@@ -48,9 +50,12 @@ 
    599770     public static final boolean TRACE_ENABLED = false; 
    600771  
     
    610781     /** 
    611782      * Table directory 
    612 @@ -549,8 +553,10 @@ 
     783@@ -549,8 +554,10 @@ 
    613784      */ 
    614785     public String getPostScriptName() { 
     
    621792         } 
    622793     } 
    623 @@ -743,6 +749,7 @@ 
     794@@ -743,6 +750,7 @@ 
    624795      * @return boolean True if it may be embedded 
    625796      */ 
     
    629800     } 
    630801  
    631 @@ -988,7 +995,10 @@ 
     802@@ -988,7 +996,10 @@ 
    632803         if (dirTabs.get("OS/2") != null) { 
    633804             seekTab(in, "OS/2", 2 * 2); 
     
    640811             if (fsType == 2) { 
    641812                 isEmbeddable = false; 
    642 @@ -996,10 +1006,21 @@ 
     813@@ -996,10 +1007,21 @@ 
    643814                 isEmbeddable = true; 
    644815             } 
     
    663834             os2Ascender = in.readTTFShort(); //sTypoAscender 
    664835             log.debug("sTypoAscender: " + os2Ascender  
    665 @@ -1568,4 +1589,8 @@ 
     836@@ -1474,6 +1496,66 @@ 
     837         } 
     838     } 
     839  
     840+    /** 
     841+     * Return TTC font names 
     842+     * @param in FontFileReader to read from 
     843+     * @return True if not collection or font name present, false otherwise 
     844+     * @throws IOException In case of an I/O problem 
     845+     */ 
     846+    public final List<String> getTTCnames(FontFileReader in) throws IOException { 
     847+        
     848+       List<String> fontNames = new java.util.ArrayList<String>(); 
     849+        
     850+        String tag = in.readTTFString(4); 
     851+ 
     852+        if ("ttcf".equals(tag)) { 
     853+            // This is a TrueType Collection 
     854+            in.skip(4); 
     855+ 
     856+            // Read directory offsets 
     857+            int numDirectories = (int)in.readTTFULong(); 
     858+            // int numDirectories=in.readTTFUShort(); 
     859+            long[] dirOffsets = new long[numDirectories]; 
     860+            for (int i = 0; i < numDirectories; i++) { 
     861+                dirOffsets[i] = in.readTTFULong(); 
     862+            } 
     863+ 
     864+            log.info("This is a TrueType collection file with " 
     865+                                   + numDirectories + " fonts"); 
     866+            log.info("Containing the following fonts: "); 
     867+            // Read all the directories and name tables to check 
     868+            // If the font exists - this is a bit ugly, but... 
     869+            boolean found = false; 
     870+ 
     871+            // Iterate through all name tables even if font 
     872+            // Is found, just to show all the names 
     873+            long dirTabOffset = 0; 
     874+            for (int i = 0; (i < numDirectories); i++) { 
     875+                in.seekSet(dirOffsets[i]); 
     876+                readDirTabs(in); 
     877+ 
     878+                readName(in); 
     879+ 
     880+                log.info(fullName); 
     881+                fontNames.add(fullName); 
     882+ 
     883+                // Reset names 
     884+                notice = ""; 
     885+                fullName = ""; 
     886+                familyNames.clear(); 
     887+                postScriptName = ""; 
     888+                subFamilyName = ""; 
     889+            } 
     890+ 
     891+            in.seekSet(0); 
     892+            return fontNames; 
     893+        } else { 
     894+               log.error("Not a TTC!"); 
     895+               return null; 
     896+        } 
     897+    } 
     898+     
     899+     
     900     /* 
     901      * Helper classes, they are not very efficient, but that really 
     902      * doesn't matter... 
     903@@ -1568,4 +1650,8 @@ 
    666904             ioe.printStackTrace(System.err); 
    667905         } 
     
    677915--- /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java (revision 631408) 
    678916+++ /home/jharrop/workspace200711/fop/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java (working copy) 
    679 @@ -92,6 +92,9 @@ 
     917@@ -51,6 +51,10 @@ 
     918      
     919     /** {@inheritDoc} */ 
     920     protected void read() throws IOException { 
     921+        read(null); 
     922+    } 
     923+ 
     924+    public void read(String ttcFontName) throws IOException { 
     925         InputStream in = openFontUri(resolver, this.fontFileURI); 
     926         try { 
     927             TTFFile ttf = new TTFFile(); 
     928@@ -55,7 +59,7 @@ 
     929         try { 
     930             TTFFile ttf = new TTFFile(); 
     931             FontFileReader reader = new FontFileReader(in); 
     932-            boolean supported = ttf.readFont(reader, null); 
     933+            boolean supported = ttf.readFont(reader, ttcFontName); 
     934             if (!supported) { 
     935                 throw new IOException("TrueType font is not supported: " + fontFileURI); 
     936             } 
     937@@ -65,7 +69,8 @@ 
     938             IOUtils.closeQuietly(in); 
     939         } 
     940     } 
     941- 
     942+     
     943+     
     944     private void buildFont(TTFFile ttf) { 
     945         if (ttf.isCFF()) { 
     946             throw new UnsupportedOperationException( 
     947@@ -92,6 +97,9 @@ 
    680948         returnFont.setMissingWidth(0); 
    681949         returnFont.setWeight(ttf.getWeightClass()); 
  • trunk/docx4j/src/main/resources/log4j.xml

    r117 r211  
    5757 
    5858    <logger name="org.docx4j.openpackaging.io"> 
    59                 <level value="info"/>  
     59                <level value="debug"/>  
    6060        </logger> 
    6161 
     
    6868        </logger> 
    6969 
     70    <logger name="org.docx4j.fonts"> 
     71                <level value="debug"/>  
     72        </logger> 
    7073   
    7174 
Note: See TracChangeset for help on using the changeset viewer.