Pārlūkot izejas kodu

Modified JPFOP PDF rendering class


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194060 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_17_0
arved pirms 23 gadiem
vecāks
revīzija
2ac2b98cb4

+ 30
- 0
jpfop-0.17.0/src/org/apache/fop/render/pdf/CIDFont.java Parādīt failu

@@ -0,0 +1,30 @@
package org.apache.fop.render.pdf;

public abstract class CIDFont extends Font {

public static final int CIDFontType0 = 0;
public static final int CIDFontType2 = 2;

// Required
public abstract String getCidBaseFont();
public abstract int getCidType();
public abstract String getCharEncoding();
public abstract String getRegistry();
public abstract String getOrdering();
public abstract int getSupplement();
// Optional
public int getDefaultWidth() { return -1; }
public Widths getWidths() { return null; }
public int getWinCharSet() { return -1; }

// Need For FOP

/**
*Returns CMap Object .
*<p>
*If this method does not return null , the mapping from character codes
*to a font number is performed in FOP . When the getCidType() method
*returns CIDFontType2 , this method must not return null .
*/
public CMap getCMap() { return null; }
}

+ 58
- 0
jpfop-0.17.0/src/org/apache/fop/render/pdf/CIDFontWidthsEntry.java Parādīt failu

@@ -0,0 +1,58 @@
package org.apache.fop.render.pdf;

/**
* This object is used for widths in CIDFonts .
* The entry of Widths for a CIDFont allows two defferent formats .
* For more details , see PDF specification p.213 .
*/
public class CIDFontWidthsEntry {
int[] widths = null;
int width = 0;
int start = 0;
int end = 0;

/**
* C [ W1 W2 ... Wn ] format entry .
*/
CIDFontWidthsEntry(int start, int[] widths) {
this.start = start;
this.end = start+widths.length;
this.widths=widths;
}

/**
* Cfirst Clast W format entry .
*/
CIDFontWidthsEntry(int start, int end, int width) {
this.start = start;
this.end = end;
this.width = width;
}

/**
* Get widths for specified code point .
*/
public int getWidth(int codePoint) throws ArrayIndexOutOfBoundsException {
if (codePoint<start || end<codePoint)
throw new ArrayIndexOutOfBoundsException();
return ( widths == null ) ? width : widths[codePoint-start];
}

public void toString(StringBuffer sb) {
sb.append(start);
if ( widths == null ) {
sb.append(" ");
sb.append(end);
sb.append(" ");
sb.append(width);
sb.append("\n");
} else {
sb.append(" [ ");
for ( int i = 0; i < widths.length; i++ ) {
sb.append(widths[i]);
sb.append(" ");
}
sb.append("]\n");
}
}
}

+ 5
- 0
jpfop-0.17.0/src/org/apache/fop/render/pdf/CMap.java Parādīt failu

@@ -0,0 +1,5 @@
package org.apache.fop.render.pdf;

public interface CMap {
public abstract char mapping(char ch);
}

+ 307
- 0
jpfop-0.17.0/src/org/apache/fop/render/pdf/FontSetup.java Parādīt failu

@@ -0,0 +1,307 @@
/*-- $Id$ --

============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Fop" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.render.pdf;

// FOP
import org.apache.fop.render.pdf.fonts.*;
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.layout.FontDescriptor;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFResources;

// Java
import java.util.Enumeration;
import java.util.Hashtable;

// For JAPANAIZED
import org.apache.fop.render.pdf.fonts.cidfont.jp.*;

/**
* sets up the PDF fonts.
*
* Assigns the font (with metrics) to internal names like "F1" and
* assigns family-style-weight triplets to the fonts
*/
public class FontSetup {

/**
* sets up the font info object.
*
* adds metrics for basic fonts and useful family-style-weight
* triplets for lookup
*
* @param fontInfo the font info object to set up
*/
public static void setup(FontInfo fontInfo) {
MessageHandler.logln("setting up fonts");
fontInfo.addMetrics("F1", new Helvetica());
fontInfo.addMetrics("F2", new HelveticaOblique());
fontInfo.addMetrics("F3", new HelveticaBold());
fontInfo.addMetrics("F4", new HelveticaBoldOblique());
fontInfo.addMetrics("F5", new TimesRoman());
fontInfo.addMetrics("F6", new TimesItalic());
fontInfo.addMetrics("F7", new TimesBold());
fontInfo.addMetrics("F8", new TimesBoldItalic());
fontInfo.addMetrics("F9", new Courier());
fontInfo.addMetrics("F10", new CourierOblique());
fontInfo.addMetrics("F11", new CourierBold());
fontInfo.addMetrics("F12", new CourierBoldOblique());
fontInfo.addMetrics("F13", new Symbol());
fontInfo.addMetrics("F14", new ZapfDingbats());
//Custom type 1 fonts step 1/2
// For JAPANIZE
fontInfo.addMetrics("F15", new MSMincho());
fontInfo.addMetrics("F16", new MSMinchoBold());
fontInfo.addMetrics("F17", new MSMinchoItalic());
fontInfo.addMetrics("F18", new MSMinchoBoldItalic());
fontInfo.addMetrics("F19", new MSGothic());
fontInfo.addMetrics("F20", new MSGothicBold());
fontInfo.addMetrics("F21", new MSGothicItalic());
fontInfo.addMetrics("F22", new MSGothicBoldItalic());
fontInfo.addMetrics("F23", new RyuminLight());
fontInfo.addMetrics("F24", new GothicBBBMedium());
// MS Font Aliases
fontInfo.addMetrics("F25", new MSMinchoAlias());
fontInfo.addMetrics("F26", new MSMinchoBoldAlias());
fontInfo.addMetrics("F27", new MSMinchoItalicAlias());
fontInfo.addMetrics("F28", new MSMinchoBoldItalicAlias());
fontInfo.addMetrics("F29", new MSGothicAlias());
fontInfo.addMetrics("F30", new MSGothicBoldAlias());
fontInfo.addMetrics("F31", new MSGothicItalicAlias());
fontInfo.addMetrics("F32", new MSGothicBoldItalicAlias());
fontInfo.addMetrics("F33", new Osaka());

/* any is treated as serif */
fontInfo.addFontProperties("F5", "any", "normal", "normal");
fontInfo.addFontProperties("F6", "any", "italic", "normal");
fontInfo.addFontProperties("F6", "any", "oblique", "normal");
fontInfo.addFontProperties("F7", "any", "normal", "bold");
fontInfo.addFontProperties("F8", "any", "italic", "bold");
fontInfo.addFontProperties("F8", "any", "oblique", "bold");

fontInfo.addFontProperties("F1", "sans-serif", "normal",
"normal");
fontInfo.addFontProperties("F2", "sans-serif", "oblique",
"normal");
fontInfo.addFontProperties("F2", "sans-serif", "italic",
"normal");
fontInfo.addFontProperties("F3", "sans-serif", "normal",
"bold");
fontInfo.addFontProperties("F4", "sans-serif", "oblique",
"bold");
fontInfo.addFontProperties("F4", "sans-serif", "italic",
"bold");
fontInfo.addFontProperties("F5", "serif", "normal", "normal");
fontInfo.addFontProperties("F6", "serif", "oblique",
"normal");
fontInfo.addFontProperties("F6", "serif", "italic", "normal");
fontInfo.addFontProperties("F7", "serif", "normal", "bold");
fontInfo.addFontProperties("F8", "serif", "oblique", "bold");
fontInfo.addFontProperties("F8", "serif", "italic", "bold");
fontInfo.addFontProperties("F9", "monospace", "normal",
"normal");
fontInfo.addFontProperties("F10", "monospace", "oblique",
"normal");
fontInfo.addFontProperties("F10", "monospace", "italic",
"normal");
fontInfo.addFontProperties("F11", "monospace", "normal",
"bold");
fontInfo.addFontProperties("F12", "monospace", "oblique",
"bold");
fontInfo.addFontProperties("F12", "monospace", "italic",
"bold");

fontInfo.addFontProperties("F1", "Helvetica", "normal",
"normal");
fontInfo.addFontProperties("F2", "Helvetica", "oblique",
"normal");
fontInfo.addFontProperties("F2", "Helvetica", "italic",
"normal");
fontInfo.addFontProperties("F3", "Helvetica", "normal",
"bold");
fontInfo.addFontProperties("F4", "Helvetica", "oblique",
"bold");
fontInfo.addFontProperties("F4", "Helvetica", "italic",
"bold");
fontInfo.addFontProperties("F5", "Times", "normal", "normal");
fontInfo.addFontProperties("F6", "Times", "oblique",
"normal");
fontInfo.addFontProperties("F6", "Times", "italic", "normal");
fontInfo.addFontProperties("F7", "Times", "normal", "bold");
fontInfo.addFontProperties("F8", "Times", "oblique", "bold");
fontInfo.addFontProperties("F8", "Times", "italic", "bold");
fontInfo.addFontProperties("F9", "Courier", "normal",
"normal");
fontInfo.addFontProperties("F10", "Courier", "oblique",
"normal");
fontInfo.addFontProperties("F10", "Courier", "italic",
"normal");
fontInfo.addFontProperties("F11", "Courier", "normal",
"bold");
fontInfo.addFontProperties("F12", "Courier", "oblique",
"bold");
fontInfo.addFontProperties("F12", "Courier", "italic",
"bold");
fontInfo.addFontProperties("F13", "Symbol", "normal",
"normal");
fontInfo.addFontProperties("F14", "ZapfDingbats", "normal",
"normal");
//Custom type 1 fonts step 2/2
// For JAPANIZE
fontInfo.addFontProperties("F15", "\uff2d\uff33\u660e\u671d", "normal",
"normal");
fontInfo.addFontProperties("F16", "\uff2d\uff33\u660e\u671d", "normal",
"bold");
fontInfo.addFontProperties("F17", "\uff2d\uff33\u660e\u671d", "italic",
"normal");
fontInfo.addFontProperties("F18", "\uff2d\uff33\u660e\u671d", "italic",
"bold");
fontInfo.addFontProperties("F19", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "normal",
"normal");
fontInfo.addFontProperties("F20", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "normal",
"bold");
fontInfo.addFontProperties("F21", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "italic",
"normal");
fontInfo.addFontProperties("F22", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "italic",
"bold");
fontInfo.addFontProperties("F23", "Ryumin-Light", "normal",
"normal");
fontInfo.addFontProperties("F23", "Ryumin-Light", "normal",
"bold");
fontInfo.addFontProperties("F23", "Ryumin-Light", "italic",
"normal");
fontInfo.addFontProperties("F23", "Ryumin-Light", "italic",
"bold");
fontInfo.addFontProperties("F24", "GothicBBB-Medium", "normal",
"normal");
fontInfo.addFontProperties("F24", "GothicBBB-Medium", "normal",
"bold");
fontInfo.addFontProperties("F24", "GothicBBB-Medium", "italic",
"normal");
fontInfo.addFontProperties("F24", "GothicBBB-Medium", "italic",
"bold");
fontInfo.addFontProperties("F25", "MS-Mincho", "normal",
"normal");
fontInfo.addFontProperties("F26", "MS-Mincho", "normal",
"bold");
fontInfo.addFontProperties("F27", "MS-Mincho", "italic",
"normal");
fontInfo.addFontProperties("F28", "MS-Mincho", "italic",
"bold");
fontInfo.addFontProperties("F29", "MS-Gothic", "normal",
"normal");
fontInfo.addFontProperties("F30", "MS-Gothic", "normal",
"bold");
fontInfo.addFontProperties("F31", "MS-Gothic", "italic",
"normal");
fontInfo.addFontProperties("F32", "MS-Gothic", "italic",
"bold");
fontInfo.addFontProperties("F33", "Osaka", "normal",
"normal");

/* for compatibility with PassiveTex */
fontInfo.addFontProperties("F5", "Times-Roman", "normal",
"normal");
fontInfo.addFontProperties("F6", "Times-Roman", "oblique",
"normal");
fontInfo.addFontProperties("F6", "Times-Roman", "italic",
"normal");
fontInfo.addFontProperties("F7", "Times-Roman", "normal",
"bold");
fontInfo.addFontProperties("F8", "Times-Roman", "oblique",
"bold");
fontInfo.addFontProperties("F8", "Times-Roman", "italic",
"bold");
fontInfo.addFontProperties("F5", "Times Roman", "normal",
"normal");
fontInfo.addFontProperties("F6", "Times Roman", "oblique",
"normal");
fontInfo.addFontProperties("F6", "Times Roman", "italic",
"normal");
fontInfo.addFontProperties("F7", "Times Roman", "normal",
"bold");
fontInfo.addFontProperties("F8", "Times Roman", "oblique",
"bold");
fontInfo.addFontProperties("F8", "Times Roman", "italic",
"bold");
fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
"normal", "normal");
}

/**
* add the fonts in the font info to the PDF document
*
* @param doc PDF document to add fonts to
* @param fontInfo font info object to get font information from
*/
public static void addToResources(PDFDocument doc, FontInfo fontInfo) {
Hashtable fonts = fontInfo.getFonts();
Enumeration e = fonts.keys();
PDFResources resources = doc.getResources();
while (e.hasMoreElements()) {
String f = (String) e.nextElement();
Font font = (Font)fonts.get(f);
FontDescriptor desc = null;
if (font instanceof FontDescriptor) {
desc = (FontDescriptor)font;
}
resources.addFont(doc.makeFont(f,
font.fontName(),
font.encoding(),
font,
desc
)
);
}
}
}

+ 1187
- 0
jpfop-0.17.0/src/org/apache/fop/render/pdf/PDFRenderer.java
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 80
- 0
jpfop-0.17.0/src/org/apache/fop/render/pdf/Widths.java Parādīt failu

@@ -0,0 +1,80 @@
package org.apache.fop.render.pdf;

import java.util.Vector;

public class Widths {
private Vector width = null;
private Vector cidWidth = null;
private int[] widths = null;

/**
* Used for Type1 , TrueType , MMType1 , Type3 fonts .
*/
public Widths() {
width = new Vector();
cidWidth = new Vector();
}

/**
* Used for Type0 fonts .
*/
public Widths( int[] widths ) {
this.widths = widths;
}

public void addWidths(int start, int end, int width ) {
(this.width).addElement(new CIDFontWidthsEntry(start,end,width));
}

public void addWidths(int start, int[] widths) {
width.addElement(new CIDFontWidthsEntry(start,widths));
}

/**
* Add Cfirst Clast W format entry .
* Used for Type0 fonts .
*/
public void addElement(int start, int end, int width ) {
cidWidth.addElement(new CIDFontWidthsEntry(start,end,width));
}

/**
* Add C [ W1 W2 ... Wn ] format entry .
* Used for Type0 fonts .
*/
public void addElement(int start, int[] widths) {
cidWidth.addElement(new CIDFontWidthsEntry(start,widths));
}

/**
* Get widths for specified code point .
*/
public int getWidth(int codePoint) {
if ( widths != null ) {
return widths[codePoint];
} else {
for(int i = 0; i < width.size(); i++) {
try {
return ((CIDFontWidthsEntry)width.elementAt(i)).getWidth(codePoint);
} catch(ArrayIndexOutOfBoundsException ex) {}
}
}
return -1;
}

public String toString() {
StringBuffer sb = new StringBuffer();
if ( widths != null ) {
for ( int i = 0; i < widths.length; i++ ) {
sb.append(widths[i]);
sb.append(" ");
}
} else {
for ( int i = 0; i < cidWidth.size(); i++ ) {
((CIDFontWidthsEntry)cidWidth.elementAt(i)).toString(sb);
}
}
return sb.toString();
}

}

Notiek ielāde…
Atcelt
Saglabāt