📄 type3streamparser.java
字号:
/**
* Copyright (c) 2003-2004, www.pdfbox.org
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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. Neither the name of pdfbox; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, 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.
*
* http://www.pdfbox.org
*
*/
package org.pdfbox.pdmodel.font;
import java.awt.Image;
import java.io.IOException;
import java.util.List;
import org.fontbox.util.BoundingBox;
import org.pdfbox.cos.COSNumber;
import org.pdfbox.cos.COSStream;
import org.pdfbox.pdmodel.graphics.xobject.PDInlinedImage;
import org.pdfbox.util.ImageParameters;
import org.pdfbox.util.PDFOperator;
import org.pdfbox.util.PDFStreamEngine;
/**
* This class will handle creating an image for a type 3 glyph.
*
* @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
* @version $Revision: 1.10 $
*/
public class Type3StreamParser extends PDFStreamEngine
{
private PDInlinedImage image = null;
private BoundingBox box = null;
/**
* This will parse a type3 stream and create an image from it.
*
* @param type3Stream The stream containing the operators to draw the image.
*
* @return The image that was created.
*
* @throws IOException If there is an error processing the stream.
*/
public Image createImage( COSStream type3Stream ) throws IOException
{
processStream( null, null, type3Stream );
return image.createImage();
}
/**
* This is used to handle an operation.
*
* @param operator The operation to perform.
* @param arguments The list of arguments.
*
* @throws IOException If there is an error processing the operation.
*/
protected void processOperator( PDFOperator operator, List arguments ) throws IOException
{
super.processOperator( operator, arguments );
String operation = operator.getOperation();
/**
if( operation.equals( "b" ) )
{
//Close, fill, and stroke path using nonzero winding number rule
}
else if( operation.equals( "B" ) )
{
//Fill and stroke path using nonzero winding number rule
}
else if( operation.equals( "b*" ) )
{
//Close, fill, and stroke path using even-odd rule
}
else if( operation.equals( "B*" ) )
{
//Fill and stroke path using even-odd rule
}
else if( operation.equals( "BDC" ) )
{
//(PDF 1.2) Begin marked-content sequence with property list
}
else **/if( operation.equals( "BI" ) )
{
ImageParameters params = operator.getImageParameters();
image = new PDInlinedImage();
image.setImageParameters( params );
image.setImageData( operator.getImageData() );
//begin inline image object
}/**
else if( operation.equals( "BMC" ) )
{
//(PDF 1.2) Begin marked-content sequence
}
else if( operation.equals( "BT" ) )
{
log.debug( "<BT>" );
textMatrix = new Matrix();
textLineMatrix = new Matrix();
}
else if( operation.equals( "BX" ) )
{
//(PDF 1.1) Begin compatibility section
}
else if( operation.equals( "c" ) )
{
//Append curved segment to path (three control points)
}
else if( operation.equals( "cm" ) )
{
}
else if( operation.equals( "cs" ) )
{
}
else if( operation.equals( "CS" ) )
{
}
else if( operation.equals( "d" ) )
{
//Set the line dash pattern in the graphics state
}
else */if( operation.equals( "d0" ) )
{
//set glyph with for a type3 font
//COSNumber horizontalWidth = (COSNumber)arguments.get( 0 );
//COSNumber verticalWidth = (COSNumber)arguments.get( 1 );
//width = horizontalWidth.intValue();
//height = verticalWidth.intValue();
}
else if( operation.equals( "d1" ) )
{
//set glyph with and bounding box for type 3 font
//COSNumber horizontalWidth = (COSNumber)arguments.get( 0 );
//COSNumber verticalWidth = (COSNumber)arguments.get( 1 );
COSNumber llx = (COSNumber)arguments.get( 2 );
COSNumber lly = (COSNumber)arguments.get( 3 );
COSNumber urx = (COSNumber)arguments.get( 4 );
COSNumber ury = (COSNumber)arguments.get( 5 );
//width = horizontalWidth.intValue();
//height = verticalWidth.intValue();
box = new BoundingBox();
box.setLowerLeftX( llx.floatValue() );
box.setLowerLeftY( lly.floatValue() );
box.setUpperRightX( urx.floatValue() );
box.setUpperRightY( ury.floatValue() );
}/*
else if( operation.equals( "Do" ) )
{
//invoke named object.
}
else if( operation.equals( "DP" ) )
{
//(PDF 1.2) De.ne marked-content point with property list
}
else if( operation.equals( "EI" ) )
{
//end inline image object
}
else if( operation.equals( "EMC" ) )
{
//End inline image object
}
else if( operation.equals( "ET" ) )
{
log.debug( "<ET>" );
textMatrix = null;
textLineMatrix = null;
}
else if( operation.equals( "EX" ) )
{
//(PDF 1.1) End compatibility section
}
else if( operation.equals( "f" ) )
{
//Fill the path, using the nonzero winding number rule to determine the region to .ll
}
else if( operation.equals( "F" ) )
{
}
else if( operation.equals( "f*" ) )
{
//Fill path using even-odd rule
}
else if( operation.equals( "g" ) )
{
}
else if( operation.equals( "G" ) )
{
}
else if( operation.equals( "gs" ) )
{
}
else if( operation.equals( "h" ) )
{
//close subpath
}
else if( operation.equals( "i" ) )
{
//set flatness tolerance, not sure what this does
}
else if( operation.equals( "ID" ) )
{
//begin inline image data
}
else if( operation.equals( "j" ) )
{
//Set the line join style in the graphics state
//System.out.println( "<j>" );
}
else if( operation.equals( "J" ) )
{
//Set the line cap style in the graphics state
//System.out.println( "<J>" );
}
else if( operation.equals( "k" ) )
{
//Set CMYK color for nonstroking operations
}
else if( operation.equals( "K" ) )
{
//Set CMYK color for stroking operations
}
else if( operation.equals( "l" ) )
{
//append straight line segment from the current point to the point.
COSNumber x = (COSNumber)arguments.get( 0 );
COSNumber y = (COSNumber)arguments.get( 1 );
linePath.lineTo( x.floatValue(), pageSize.getHeight()-y.floatValue() );
}
else if( operation.equals( "m" ) )
{
COSNumber x = (COSNumber)arguments.get( 0 );
COSNumber y = (COSNumber)arguments.get( 1 );
linePath.reset();
linePath.moveTo( x.floatValue(), pageSize.getHeight()-y.floatValue() );
//System.out.println( "<m x=\"" + x.getValue() + "\" y=\"" + y.getValue() + "\" >" );
}
else if( operation.equals( "M" ) )
{
//System.out.println( "<M>" );
}
else if( operation.equals( "MP" ) )
{
//(PDF 1.2) Define marked-content point
}
else if( operation.equals( "n" ) )
{
//End path without .lling or stroking
//System.out.println( "<n>" );
}
else if( operation.equals( "q" ) )
{
//save graphics state
if( log.isDebugEnabled() )
{
log.debug( "<" + operation + "> - save state" );
}
graphicsStack.push(graphicsState.clone());
}
else if( operation.equals( "Q" ) )
{
//restore graphics state
if( log.isDebugEnabled() )
{
log.debug( "<" + operation + "> - restore state" );
}
graphicsState = (PDGraphicsState)graphicsStack.pop();
}
else if( operation.equals( "re" ) )
{
}
else if( operation.equals( "rg" ) )
{
//Set RGB color for nonstroking operations
}
else if( operation.equals( "RG" ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -