diff options
Diffstat (limited to 'src/java/org/apache/fop/fonts/autodetect')
9 files changed, 0 insertions, 817 deletions
diff --git a/src/java/org/apache/fop/fonts/autodetect/FontDirFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontDirFinder.java deleted file mode 100644 index 383c5283d..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/FontDirFinder.java +++ /dev/null @@ -1,41 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -/** - * Implementers provide find method for searching native operating system - * for available fonts. - */ -public interface FontDirFinder { - - /** - * Finds a list of font files. - * - * @return list of font files. - * @throws IOException - * In case of an I/O problem - */ - List<File> find() throws IOException; - -} diff --git a/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java deleted file mode 100644 index 8100c4b9b..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java +++ /dev/null @@ -1,179 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collection; -import java.util.List; - -import org.apache.commons.io.DirectoryWalker; -import org.apache.commons.io.IOCase; -import org.apache.commons.io.filefilter.FileFilterUtils; -import org.apache.commons.io.filefilter.IOFileFilter; -import org.apache.commons.io.filefilter.WildcardFileFilter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.fop.fonts.FontEventListener; - -/** - * Helps to autodetect/locate available operating system fonts. - */ -public class FontFileFinder extends DirectoryWalker implements FontFinder { - - /** logging instance */ - private final Log log = LogFactory.getLog(FontFileFinder.class); - - /** default depth limit of recursion when searching for font files **/ - public static final int DEFAULT_DEPTH_LIMIT = -1; - private final FontEventListener eventListener; - - /** - * Default constructor - * @param listener for throwing font related events - */ - public FontFileFinder(FontEventListener listener) { - this(DEFAULT_DEPTH_LIMIT, listener); - } - - /** - * Constructor - * @param depthLimit recursion depth limit - * @param listener for throwing font related events - */ - public FontFileFinder(int depthLimit, FontEventListener listener) { - super(getDirectoryFilter(), getFileFilter(), depthLimit); - eventListener = listener; - } - - /** - * Font directory filter. Currently ignores hidden directories. - * @return IOFileFilter font directory filter - */ - protected static IOFileFilter getDirectoryFilter() { - return FileFilterUtils.andFileFilter( - FileFilterUtils.directoryFileFilter(), - FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter(".")) - ); - } - - /** - * Font file filter. Currently searches for files with .ttf, .ttc, .otf, and .pfb extensions. - * @return IOFileFilter font file filter - */ - protected static IOFileFilter getFileFilter() { - return FileFilterUtils.andFileFilter( - FileFilterUtils.fileFileFilter(), - new WildcardFileFilter( - new String[] {"*.ttf", "*.otf", "*.pfb", "*.ttc"}, - IOCase.INSENSITIVE) - ); - } - - /** - * @param directory directory to handle - * @param depth recursion depth - * @param results collection - * @return whether directory should be handled - * {@inheritDoc} - */ - @Override - protected boolean handleDirectory(File directory, int depth, Collection results) { - return true; - } - - /** - * @param file file to handle - * @param depth recursion depth - * @param results collection - * {@inheritDoc} - */ - @Override - protected void handleFile(File file, int depth, Collection results) { - try { - // Looks Strange, but is actually recommended over just .URL() - results.add(file.toURI().toURL()); - } catch (MalformedURLException e) { - log.debug("MalformedURLException" + e.getMessage()); - } - } - - /** - * @param directory the directory being processed - * @param depth the current directory level - * @param results the collection of results objects - * {@inheritDoc} - */ - @Override - protected void handleDirectoryEnd(File directory, int depth, Collection results) { - if (log.isDebugEnabled()) { - log.debug(directory + ": found " + results.size() + " font" - + ((results.size() == 1) ? "" : "s")); - } - } - - /** - * Automagically finds a list of font files on local system - * - * @return List<URL> of font files - * @throws IOException io exception - * {@inheritDoc} - */ - public List<URL> find() throws IOException { - final FontDirFinder fontDirFinder; - final String osName = System.getProperty("os.name"); - if (osName.startsWith("Windows")) { - fontDirFinder = new WindowsFontDirFinder(); - } else { - if (osName.startsWith("Mac")) { - fontDirFinder = new MacFontDirFinder(); - } else { - fontDirFinder = new UnixFontDirFinder(); - } - } - List<File> fontDirs = fontDirFinder.find(); - List<URL> results = new java.util.ArrayList<URL>(); - for (File dir : fontDirs) { - super.walk(dir, results); - } - return results; - } - - /** - * Searches a given directory for font files - * - * @param dir directory to search - * @return list of font files - * @throws IOException thrown if an I/O exception of some sort has occurred - */ - public List<URL> find(String dir) throws IOException { - List<URL> results = new java.util.ArrayList<URL>(); - File directory = new File(dir); - if (!directory.isDirectory()) { - eventListener.fontDirectoryNotFound(this, dir); - } else { - super.walk(directory, results); - } - return results; - } -} diff --git a/src/java/org/apache/fop/fonts/autodetect/FontFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontFinder.java deleted file mode 100644 index 51e79443a..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/FontFinder.java +++ /dev/null @@ -1,41 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -import java.io.IOException; -import java.net.URL; -import java.util.List; - -/** - * Implementers provide find method for searching native operating system - * for available fonts. - */ -public interface FontFinder { - - /** - * Finds a list of font files. - * - * @return list of font files. - * @throws IOException - * In case of an I/O problem - */ - List<URL> find() throws IOException; - -} diff --git a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java deleted file mode 100644 index a1d65459a..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java +++ /dev/null @@ -1,279 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -import java.io.InputStream; -import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.regex.Pattern; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.fop.apps.io.InternalResourceResolver; -import org.apache.fop.fonts.CustomFont; -import org.apache.fop.fonts.EmbedFontInfo; -import org.apache.fop.fonts.EmbeddingMode; -import org.apache.fop.fonts.EncodingMode; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.FontCache; -import org.apache.fop.fonts.FontEventListener; -import org.apache.fop.fonts.FontLoader; -import org.apache.fop.fonts.FontTriplet; -import org.apache.fop.fonts.FontUris; -import org.apache.fop.fonts.FontUtil; -import org.apache.fop.fonts.MultiByteFont; -import org.apache.fop.fonts.truetype.FontFileReader; -import org.apache.fop.fonts.truetype.OFFontLoader; -import org.apache.fop.fonts.truetype.TTFFile; - -/** - * Attempts to determine correct FontInfo - */ -public class FontInfoFinder { - - /** logging instance */ - private final Log log = LogFactory.getLog(FontInfoFinder.class); - - private FontEventListener eventListener; - - /** - * Sets the font event listener that can be used to receive events about particular events - * in this class. - * @param listener the font event listener - */ - public void setEventListener(FontEventListener listener) { - this.eventListener = listener; - } - - /** - * Attempts to determine FontTriplets from a given CustomFont. - * It seems to be fairly accurate but will probably require some tweaking over time - * - * @param customFont CustomFont - * @param triplets Collection that will take the generated triplets - */ - private void generateTripletsFromFont(CustomFont customFont, Collection<FontTriplet> triplets) { - if (log.isTraceEnabled()) { - log.trace("Font: " + customFont.getFullName() - + ", family: " + customFont.getFamilyNames() - + ", PS: " + customFont.getFontName() - + ", EmbedName: " + customFont.getEmbedFontName()); - } - - // default style and weight triplet vales (fallback) - String strippedName = stripQuotes(customFont.getStrippedFontName()); - //String subName = customFont.getFontSubName(); - String fullName = stripQuotes(customFont.getFullName()); - String searchName = fullName.toLowerCase(); - - String style = guessStyle(customFont, searchName); - int weight; //= customFont.getWeight(); - int guessedWeight = FontUtil.guessWeight(searchName); - //We always take the guessed weight for now since it yield much better results. - //OpenType's OS/2 usWeightClass value proves to be unreliable. - weight = guessedWeight; - - //Full Name usually includes style/weight info so don't use these traits - //If we still want to use these traits, we have to make FontInfo.fontLookup() smarter - triplets.add(new FontTriplet(fullName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)); - if (!fullName.equals(strippedName)) { - triplets.add(new FontTriplet(strippedName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)); - } - Set<String> familyNames = customFont.getFamilyNames(); - for (String familyName : familyNames) { - familyName = stripQuotes(familyName); - if (!fullName.equals(familyName)) { - /* Heuristic: - * The more similar the family name to the full font name, - * the higher the priority of its triplet. - * (Lower values indicate higher priorities.) */ - int priority = fullName.startsWith(familyName) - ? fullName.length() - familyName.length() - : fullName.length(); - triplets.add(new FontTriplet(familyName, style, weight, priority)); - } - } - } - - private final Pattern quotePattern = Pattern.compile("'"); - - private String stripQuotes(String name) { - return quotePattern.matcher(name).replaceAll(""); - } - - private String guessStyle(CustomFont customFont, String fontName) { - // style - String style = Font.STYLE_NORMAL; - if (customFont.getItalicAngle() > 0) { - style = Font.STYLE_ITALIC; - } else { - style = FontUtil.guessStyle(fontName); - } - return style; - } - - /** - * Attempts to determine FontInfo from a given custom font - * @param fontUri the font URI - * @param customFont the custom font - * @param fontCache font cache (may be null) - * @return FontInfo from the given custom font - */ - private EmbedFontInfo getFontInfoFromCustomFont(URI fontUri, CustomFont customFont, - FontCache fontCache, InternalResourceResolver resourceResolver) { - FontUris fontUris = new FontUris(fontUri, null); - List<FontTriplet> fontTripletList = new java.util.ArrayList<FontTriplet>(); - generateTripletsFromFont(customFont, fontTripletList); - String subFontName = null; - if (customFont instanceof MultiByteFont) { - subFontName = ((MultiByteFont) customFont).getTTCName(); - } - EmbedFontInfo fontInfo = new EmbedFontInfo(fontUris, customFont.isKerningEnabled(), - customFont.isAdvancedEnabled(), fontTripletList, subFontName, - EncodingMode.AUTO, EmbeddingMode.AUTO); - fontInfo.setPostScriptName(customFont.getFontName()); - if (fontCache != null) { - fontCache.addFont(fontInfo, resourceResolver); - } - return fontInfo; - } - - /** - * Attempts to determine EmbedFontInfo from a given font file. - * - * @param fontURI the URI of the font resource - * @param resourceResolver font resolver used to resolve font - * @param fontCache font cache (may be null) - * @return an array of newly created embed font info. Generally, this array - * will have only one entry, unless the fontUrl is a TrueType Collection - */ - public EmbedFontInfo[] find(URI fontURI, InternalResourceResolver resourceResolver, FontCache fontCache) { - URI embedUri = resourceResolver.resolveFromBase(fontURI); - String embedStr = embedUri.toASCIIString(); - boolean useKerning = true; - boolean useAdvanced = true; - - long fileLastModified = -1; - if (fontCache != null) { - fileLastModified = FontCache.getLastModified(fontURI); - // firstly try and fetch it from cache before loading/parsing the font file - if (fontCache.containsFont(embedStr)) { - EmbedFontInfo[] fontInfos = fontCache.getFontInfos(embedStr, fileLastModified); - if (fontInfos != null) { - return fontInfos; - } - // is this a previously failed parsed font? - } else if (fontCache.isFailedFont(embedStr, fileLastModified)) { - if (log.isDebugEnabled()) { - log.debug("Skipping font file that failed to load previously: " + embedUri); - } - return null; - } - } - - - // try to determine triplet information from font file - CustomFont customFont = null; - if (fontURI.toASCIIString().toLowerCase().endsWith(".ttc")) { - // Get a list of the TTC Font names - List<String> ttcNames = null; - InputStream in = null; - try { - in = resourceResolver.getResource(fontURI); - TTFFile ttf = new TTFFile(false, false); - FontFileReader reader = new FontFileReader(in); - ttcNames = ttf.getTTCnames(reader); - } catch (Exception e) { - if (this.eventListener != null) { - this.eventListener.fontLoadingErrorAtAutoDetection(this, - fontURI.toASCIIString(), e); - } - return null; - } finally { - IOUtils.closeQuietly(in); - } - - List<EmbedFontInfo> embedFontInfoList = new java.util.ArrayList<EmbedFontInfo>(); - - // For each font name ... - for (String fontName : ttcNames) { - if (log.isDebugEnabled()) { - log.debug("Loading " + fontName); - } - try { - OFFontLoader ttfLoader = new OFFontLoader(fontURI, fontName, true, - EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced, - resourceResolver); - customFont = ttfLoader.getFont(); - if (this.eventListener != null) { - customFont.setEventListener(this.eventListener); - } - } catch (Exception e) { - if (fontCache != null) { - fontCache.registerFailedFont(embedUri.toASCIIString(), fileLastModified); - } - if (this.eventListener != null) { - this.eventListener.fontLoadingErrorAtAutoDetection(this, - embedUri.toASCIIString(), e); - } - continue; - } - EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, - resourceResolver); - if (fi != null) { - embedFontInfoList.add(fi); - } - } - return embedFontInfoList.toArray( - new EmbedFontInfo[embedFontInfoList.size()]); - } else { - // The normal case - try { - FontUris fontUris = new FontUris(fontURI, null); - customFont = FontLoader.loadFont(fontUris, null, true, EmbeddingMode.AUTO, EncodingMode.AUTO, - useKerning, useAdvanced, resourceResolver); - if (this.eventListener != null) { - customFont.setEventListener(this.eventListener); - } - } catch (Exception e) { - if (fontCache != null) { - fontCache.registerFailedFont(embedUri.toASCIIString(), fileLastModified); - } - if (this.eventListener != null) { - this.eventListener.fontLoadingErrorAtAutoDetection(this, - embedUri.toASCIIString(), e); - } - return null; - } - EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, resourceResolver); - if (fi != null) { - return new EmbedFontInfo[] {fi}; - } else { - return null; - } - } - - } - -} diff --git a/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java b/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java deleted file mode 100644 index 1231badf2..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java +++ /dev/null @@ -1,39 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -/** - * Mac font directory finder - */ -public class MacFontDirFinder extends NativeFontDirFinder { - - /** - * Some guesses at possible unix font directory locations - * @return a array of possible font directory locations - */ - protected String[] getSearchableDirectories() { - return new String[] { - System.getProperty("user.home") + "/Library/Fonts/", // user - "/Library/Fonts/", // local - "/System/Library/Fonts/", // system - "/Network/Library/Fonts/" // network - }; - } -} diff --git a/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java b/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java deleted file mode 100644 index 9f723a308..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java +++ /dev/null @@ -1,55 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -import java.io.File; -import java.util.List; - -/** - * Native font finder base class - */ -public abstract class NativeFontDirFinder implements FontDirFinder { - - /** - * Generic method used by Mac and Unix font finders. - * @return list of natively existing font directories - * {@inheritDoc} - */ - public List<File> find() { - List<File> fontDirList = new java.util.ArrayList<File>(); - String[] searchableDirectories = getSearchableDirectories(); - if (searchableDirectories != null) { - for (int i = 0; i < searchableDirectories.length; i++) { - File fontDir = new File(searchableDirectories[i]); - if (fontDir.exists() && fontDir.canRead()) { - fontDirList.add(fontDir); - } - } - } - return fontDirList; - } - - /** - * Returns an array of directories to search for fonts in. - * @return an array of directories - */ - protected abstract String[] getSearchableDirectories(); - -} diff --git a/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java b/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java deleted file mode 100644 index b6d596f03..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java +++ /dev/null @@ -1,40 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -/** - * Unix font directory finder - */ -public class UnixFontDirFinder extends NativeFontDirFinder { - - /** - * Some guesses at possible unix font directory locations - * @return a list of possible font locations - */ - protected String[] getSearchableDirectories() { - return new String[] { - System.getProperty("user.home") + "/.fonts", // user - "/usr/local/fonts", // local - "/usr/local/share/fonts", // local shared - "/usr/share/fonts", // system - "/usr/X11R6/lib/X11/fonts" // X - }; - } -} diff --git a/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java b/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java deleted file mode 100644 index bd506d9ed..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java +++ /dev/null @@ -1,120 +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. - */ - -/* $Id$ */ - -package org.apache.fop.fonts.autodetect; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.List; - -import org.apache.commons.io.IOUtils; - -/** - * FontFinder for native Windows platforms - */ -public class WindowsFontDirFinder implements FontDirFinder { - - /** - * Attempts to read windir environment variable on windows - * (disclaimer: This is a bit dirty but seems to work nicely) - */ - private String getWinDir(String osName) throws IOException { - Process process = null; - Runtime runtime = Runtime.getRuntime(); - if (osName.startsWith("Windows 9")) { - process = runtime.exec("command.com /c echo %windir%"); - } else { - process = runtime.exec("cmd.exe /c echo %windir%"); - } - InputStreamReader isr = null; - BufferedReader bufferedReader = null; - String dir = ""; - try { - isr = new InputStreamReader(process.getInputStream()); - bufferedReader = new BufferedReader(isr); - dir = bufferedReader.readLine(); - } finally { - IOUtils.closeQuietly(bufferedReader); - IOUtils.closeQuietly(isr); - } - return dir; - } - - /** - * {@inheritDoc} - * @return a list of detected font files - */ - public List<File> find() { - List<File> fontDirList = new java.util.ArrayList<File>(); - String windir = null; - try { - windir = System.getProperty("env.windir"); - } catch (SecurityException e) { - // should continue if this fails - } - String osName = System.getProperty("os.name"); - if (windir == null) { - try { - windir = getWinDir(osName); - } catch (IOException e) { - // should continue if this fails - } - } - File osFontsDir = null; - File psFontsDir = null; - if (windir != null) { - // remove any trailing '/' - if (windir.endsWith("/")) { - windir = windir.substring(0, windir.length() - 1); - } - osFontsDir = new File(windir + File.separator + "FONTS"); - if (osFontsDir.exists() && osFontsDir.canRead()) { - fontDirList.add(osFontsDir); - } - psFontsDir = new File(windir.substring(0, 2) + File.separator + "PSFONTS"); - if (psFontsDir.exists() && psFontsDir.canRead()) { - fontDirList.add(psFontsDir); - } - } else { - String windowsDirName = osName.endsWith("NT") ? "WINNT" : "WINDOWS"; - // look for true type font folder - for (char driveLetter = 'C'; driveLetter <= 'E'; driveLetter++) { - osFontsDir = new File( - driveLetter + ":" - + File.separator + windowsDirName - + File.separator + "FONTS"); - if (osFontsDir.exists() && osFontsDir.canRead()) { - fontDirList.add(osFontsDir); - break; - } - } - // look for type 1 font folder - for (char driveLetter = 'C'; driveLetter <= 'E'; driveLetter++) { - psFontsDir = new File(driveLetter + ":" + File.separator + "PSFONTS"); - if (psFontsDir.exists() && psFontsDir.canRead()) { - fontDirList.add(psFontsDir); - break; - } - } - } - return fontDirList; - } -} diff --git a/src/java/org/apache/fop/fonts/autodetect/package.html b/src/java/org/apache/fop/fonts/autodetect/package.html deleted file mode 100644 index 0a29acbb1..000000000 --- a/src/java/org/apache/fop/fonts/autodetect/package.html +++ /dev/null @@ -1,23 +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. ---> -<!-- $Id: $ --> -<HTML> -<TITLE>org.apache.fop.fonts.autodetect Package</TITLE> -<BODY> -<P>A collection of classes that aid in the autodetection of installed system fonts.</P> -</BODY> -</HTML> |