org.jpedal.render.output.OutputDisplay Maven / Gradle / Ivy
The newest version!
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/java-pdf-library-support/
*
* (C) Copyright 1997-2013, IDRsolutions and Contributors.
*
* This file is part of JPedal
*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---------------
* OutputDisplay.java
* ---------------
*/
package org.jpedal.render.output;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.jpedal.color.ColorSpaces;
import org.jpedal.color.PdfPaint;
import org.jpedal.fonts.PdfFont;
import org.jpedal.fonts.StandardFonts;
import org.jpedal.fonts.glyph.PdfGlyph;
import org.jpedal.io.ObjectStore;
import org.jpedal.objects.GraphicsState;
import org.jpedal.objects.PdfPageData;
import org.jpedal.objects.TextState;
import org.jpedal.objects.acroforms.rendering.AcroRenderer;
import org.jpedal.parser.Cmd;
import org.jpedal.render.BaseDisplay;
import org.jpedal.render.DynamicVectorRenderer;
import org.jpedal.render.output.io.CustomIO;
import org.jpedal.render.output.io.DefaultIO;
import org.jpedal.utils.LogWriter;
import org.jpedal.utils.Matrix;
import org.jpedal.utils.StringUtils;
import org.jpedal.utils.repositories.Vector_Rectangle;
public class OutputDisplay extends BaseDisplay {
// alt name for page 1
protected String firstPageName;
public static boolean convertT1Fonts = true;
protected String packageName = "", javaFxFileName = "";
protected HashMap fontsToConvert = new HashMap();
protected HashMap> widths = new HashMap>();
protected static boolean enableOTFConversion = false;
// flag to show embedded fonts present so need to use full name
protected boolean hasEmbeddedFonts = false;
/** track the embedded fonts we might embed */
protected Map embeddedFonts = new HashMap();
/** track by full name as well */
protected Map baseFontNames = new HashMap();
/** show if any embedded fonts in Map */
protected boolean hasEmbededFonts = false;
/** track images written out to reduce IO if already drawn */
private Map imagesAlreadyWritten = new HashMap();
protected AcroRenderer acroRenderer;
// offset in single page mode for svg
// protected double newTotalHeight = 0;
// page range
protected int startPage, endPage;
protected int pageGap = 50;
String lastGlyf = "";
boolean keepOriginalImage = false;
protected String isOnlineConverter;
protected boolean requiresTransform = false;
protected boolean requiresTransformGlobal = false;
protected boolean requiresTextGlobal = false;
final public static int TEXT_AS_TEXT = -1;
final public static int TEXT_AS_SHAPE = 1;
final public static int TEXT_INVISIBLE_ON_IMAGE = 2;
final public static int TEXT_VISIBLE_ON_IMAGE = 3;
final public static int HTML_VIEW_MULTIFILE = 1;
final public static int SVG_VIEW_MULTIFILE = 2;
final public static int HTML_VIEW_MULTIFILE_SPLITSPREADS = 3;
final public static int SVG_VIEW_MULTIFILE_SPLITSPREADS = 4;
final public static int HTML_VIEW_SINGLEFILE = 5;
final public static int SVG_VIEW_SINGLEFILE = 6;
final public static int HTML_VIEW_SINGLEFILE_SPLITSPREADS = 7;
final public static int SVG_VIEW_SINGLEFILE_SPLITSPREADS = 8;
final public static int HTML_VIEW_SINGLEFILE_HORIZONTAL = 9;
final public static int SVG_VIEW_SINGLEFILE_HORIZONTAL = 10;
protected String clip = null;
// provides common static functions
static protected org.jpedal.render.output.OutputHelper Helper = null;
FontMapper fontMapper = null;
String lastFontUsed = "";
private Map usedFontIDs = new HashMap();
protected boolean includeClip = false;
protected int textMode = -1;
protected Map embeddedFontsByFontID = new HashMap();
/** track if JS for glyf already inserted */
private Map glyfsRasterized = new HashMap();
final public static int MaxNumberOfDecimalPlaces = 0;
final public static int FontMode = 1;
final public static int PercentageScaling = 2;
// final public static int SpacingPercentage=3;
final public static int IncludeJSFontResizingCode = 4;
final public static int ExcludeMetadata = 6;
final public static int EmbedImageAsBase64Stream = 7;
final public static int AddNavBar = 8;
final public static int UseCharSpacing = 10;
final public static int UseWordSpacing = 11;
final public static int UseFontResizing = 12;
final public static int HasJavascript = 13;
final public static int ConvertSpacesTonbsp = 14;
final public static int EncloseContentInDiv = 15;
final public static int IncludeClip = 16;
final public static int UseImagesOnNavBar = 17;
final public static int TextMode = 18; // e.g. TEXT_AS_TEXT, TEXT_VISIBLE_ON_IMAGE
final public static int DisplayMode = 19; // e.g. HTML_VIEW_MULTIFILE, SVG_VIEW_SINGLEFILE
final public static int CustomIO = 21;
final public static int StartOfDecode = 22;
final public static int EndOfDecode = 23;
final public static int EmulateEvenOdd = 24;
final public static int HTMLImageMode = 26;
final public static int UseThumbnailNavbar = 27;
final public static int AcroRenderer = 28;
final public static int AddTwitterButton = 30;
final public static int AddFacebookButton = 31;
final public static int AddGooglePlusButton = 32;
final public static int AddRedditButton = 33;
final public static int AddLinkedInButton = 34;
final public static int AddDiggButton = 35;
final public static int AddStumbleUponButton = 36;
final public static int AddTumblrButton = 37;
/** ie file we Launch via button from form */
final public static int ConvertPDFExternalFileToOutputType = 38;
final public static int GetIsSinglePage = 39;
// Allow us to add a border if needed (SVG only)
final public static int AddBorder = 40;
public static final int IsSVGMode = 44;
public static final int IsTextSelectable = 45;
public static final int IsRealText = 46;
public static final int DisableImageFallback = 47;
public static final int PageTurning = 55;
public static final int AddJavaScript = 56;
public static final int EmbedImagesAsBase64 = 58;
public static final int Base64Background = 59;
public static final int DrawInvisibleText = 61;
public static final int FontsToRasterizeInTextMode = 62;
public static final int IsIDRViewer = 63;
// hold a default value set via JVM flag for font mapping
protected int defaultMode = FontMapper.DEFAULT_ON_UNMAPPED;
protected int fontMode = FontMapper.DEFAULT_ON_UNMAPPED;
// only output to 1 page
protected boolean isSingleFileOutput = false;
// visible or invisible text on image
protected boolean htmlImageMode = false;
// give user option to embed image inside HTML5
protected boolean embedImageAsBase64 = false;
private boolean groupGlyphsInTJ = true;
// allow us to position every glyf on its own and not try to merge into strings*/
protected boolean writeEveryGlyf = false;
// control whether CSS inlined in HTML file or in own css file
public boolean inlineCSS = false;
/** debug flags */
static final public boolean debugForms = false;
final private static boolean DISABLE_IMAGES = false;
final private static boolean DISABLE_SHAPE = false;
final private static boolean DISABLE_TEXT = false;
protected final static boolean DEBUG_TEXT_AREA = false;
protected final static boolean DEBUG_DRAW_PAGE_BORDER = false;
public final static int TOFILE = 0;
public final static int TOP_SECTION = 1;
public final static int SCRIPT = 2;
public final static int FORM = 3;
public final static int CSS = 4;
public final static int TEXT = 6;
public final static int KEEP_GLYFS_SEPARATE = 7;
public final static int SET_ENCODING_USED = 8;
public final static int JSIMAGESPECIAL = 9;
public final static int SAVE_EMBEDDED_FONT = 10;
public final static int PAGEDATA = 11;
public final static int IMAGE_CONTROLLER = 12;
public final static int FXMLPDFSTAGE = 13;
public final static int FONT_AS_SHAPE = 14;
public final static int FXMLTEXT = 15;
public final static int FORMJS = 16;
public final static int FORMJS_ONLOAD = 17;
public final static int NAVBAR = 18;
public final static int EXTERNAL_JS = 19;
public final static int TEXTJS = 20;
public static final int CALCULATION_ORDER = 21;
public static final int SVGINHTML = 22;
public static final int SVGCLIPS = 23;
public static final int SVGBUFFER = 25;
public static final int DVR = 26;
public static final int LEGACY_CSS = 28;
public static final int BOOKMARK = 29;
//public static final int CustomIO = 31;
public static final int HasJavaScript =32;
public static final int THUMBNAIL_DISPLAY=35;
public static final int IMAGE_DISPLAY=37;
public static final int COMPATABILITY_DISPLAY=38;
protected OutputImageController imageController = null;
protected StringBuilder script = new StringBuilder(10000);
protected ArrayList fxScript = new ArrayList();
protected ArrayList fxmlText = new ArrayList();
protected HashMap base64Images = new HashMap();
protected HashMap base64Shades = new HashMap();
protected StringBuilder fonts_as_shapes = new StringBuilder(10000);
protected StringBuilder formJS = new StringBuilder(10000);
protected StringBuilder formJSOnLoad = new StringBuilder(10000);
protected StringBuilder form = new StringBuilder(10000);
protected StringBuilder testDivs = new StringBuilder(10000);
protected StringBuilder css = new StringBuilder(10000);
protected StringBuilder topSection = new StringBuilder(10000);
protected StringBuilder fxmlPDFStage = new StringBuilder(10000);
protected StringBuilder navbarSection = new StringBuilder(10000);
protected StringBuilder externalJSFile = new StringBuilder(10000);
protected StringBuilder textJS = new StringBuilder(3000);
// @Leon TODO - We could probably be less wasteful with these figures. They are initial capacities, after all.
/** allow user to control scaling of images */
protected boolean userControlledImageScaling = false;
protected boolean emulateEvenOdd = false;
/** current text element number if using Divs. Used as link to CSS */
protected int textID = 1;
protected int shadeId = 0;
protected int imageId = 0;
/** number of decimal places on numbers */
protected int dpCount = 0;
public String rootDir = null, fileName = null;
protected int dx;
protected int dy;
protected int dr;
protected boolean excludeMetadata = false;
private boolean convertSpacesTonbsp = false;
/** include a user nav tollbar in output */
protected boolean addNavBar = false, useImagesOnNavBar = false;
protected boolean useThumbnailNavbar = false;
/** Controls blocks of text so they can be joined up */
protected TextBlock currentTextBlock;
protected TextBlock previousTextBlock;
protected TextPosition currentTextPosition;
protected Rectangle2D cropBox;
protected Point2D midPoint;
/** Used to reduce canvas color javascript calls between text and shapes */
protected int currentColor = 0;
/** control for encodings Java/CSS */
protected String[] encodingType = new String[] { "UTF-8", "utf-8" };
protected static final int JAVA_TYPE = 0;
protected static final int OUTPUT_TYPE = 1;
public static final int FORM_TAG = 0;
protected float scaling = 1.0f; // Scale to large and images may be lost due to lack of memory.
// amount of font change needed
protected int fontChangeNeeded = -1;
// Should we add a border to page (currently only used by SVG)
protected boolean addBorder = true;
// protected float spacingNeeded=1.0f; //amount of space needed
float w;
protected float h; // override int super.w and super.h for better accuracy. @Shit
protected String[] tag = { "