org.jpedal.fonts.glyph.T1GlyphFX Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of OpenViewerFX Show documentation
Show all versions of OpenViewerFX Show documentation
An Open Source JavaFX PDF Viewer
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/support/
*
* (C) Copyright 1997-2016 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
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
*
* ---------------
* T1GlyphFX.java
* ---------------
*/
package org.jpedal.fonts.glyph;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.io.IOException;
import java.io.ObjectOutput;
import javafx.collections.ObservableList;
import javafx.scene.shape.*;
import org.jpedal.color.PdfTexturePaint;
import org.jpedal.io.PathSerializer;
import org.jpedal.objects.GraphicsState;
import org.jpedal.utils.repositories.Vector_Path;
/**
* defines the current shape which is created by command stream
* This class is NOT part of the API
.
* Shapes can be drawn onto pdf or used as a clip on other image/shape/text.
* Shape is built up by storing commands and then turning these commands into a
* shape. Has to be done this way as Winding rule is not necessarily
* declared at start.
*/
public class T1GlyphFX extends BaseT1Glyph
{
/** marked as transient so it wont be serialized */
private transient Vector_Path cached_current_path;
private Paint strokePaint;
float[] x,y,x2,y2,x3,y3;
float ymin;
int end;
int[] commands;
public T1GlyphFX(){}
/**
* store scaling factors
*/
public T1GlyphFX(final float[] x, final float[] y, final float[] x2, final float[] y2, final float[] x3, final float[] y3, final float ymin, final int end, final int[] commands){
this.x=x;
this.y=y;
this.x2=x2;
this.y2=y2;
this.x3=x3;
this.y3=y3;
this.ymin=ymin;
this.end=end;
this.commands=commands;
}
//////////////////////////////////////////////////////////////////////////
/**
* turn shape commands into a Shape object, storing info for later. Has to
* be done this way because we need the winding rule to initialise the shape
* in Java, and it could be set awywhere in the command stream
*/
@Override
public void render(final int text_fill_type, final Graphics2D g2, final float scaling, final boolean isFormGlyph)
{
if(cached_current_path!=null){
//Shape c=g2.getClip();
//
// g2.setClip(null);
//
// g2.setPaint(Color.RED);
// g2.fillRect(0, 0, 300, 600);
// g2.setPaint(Color.BLUE);
// g2.fillRect(300, 0, 300, 600);
// g2.drawLine(0,0,600,600);
// g2.setClip(c);
//
//
final GeneralPath[] paths=cached_current_path.get();
for (final GeneralPath path : paths) {
if (path == null) {
break;
}
if ((text_fill_type == GraphicsState.FILL)) {
//replicate shadow effect
if (isStroked) {
final Paint fillPaint = g2.getPaint();
if (!(fillPaint instanceof PdfTexturePaint) && ((Color) strokePaint).getRGB() != ((Color) fillPaint).getRGB() &&
strokedPositions.containsKey(String.valueOf((int) g2.getTransform().getTranslateX()) + '-' + (int) g2.getTransform().getTranslateY())) {
final Stroke fillStroke = g2.getStroke();
g2.setPaint(strokePaint);
float w = (float) (scaling / g2.getTransform().getScaleX());
if (w < 0) {
w = -w;
}
g2.setStroke(new BasicStroke(w));
g2.draw(path);
g2.setPaint(fillPaint);
g2.setStroke(fillStroke);
//System.out.println(this.getID()+" "+this.getGlyphName());
}
}
g2.fill(path);
}
if (text_fill_type == GraphicsState.STROKE) {
//ensure visible if just stroke
if (text_fill_type != GraphicsState.FILL && scaling > 1.0f) {
// System.out.println(">>"+glyfwidth+" "+scaling+" "+g2.getTransform()+" "+g2.getTransform().getScaleX());
float w = (float) (scaling / g2.getTransform().getScaleX());
if (w < 0) {
w = -w;
}
g2.setStroke(new BasicStroke(w));
//g2.setStroke(new BasicStroke(200));
//System.out.println(((scaling/g2.getTransform().getScaleX())));
}
g2.draw(path);
strokePaint = g2.getPaint();
strokedPositions.put(String.valueOf((int) g2.getTransform().getTranslateX()) + '-' + (int) g2.getTransform().getTranslateY(), "x");
}
}
}
}
Area glyphShape;
/**return shape of glyph*/
@Override
public Area getShape() {
if((cached_current_path!=null && glyphShape==null)){
final GeneralPath[] paths=cached_current_path.get();
final int cacheCount=paths.length;
for(int i=1;ib.x) {
minX = b.x;
}
if(minY>b.y) {
minY = b.y;
}
if(maxX elements = currentPath.getElements();
elements.add(new MoveTo(0,0));
//init points
int i = 0;
//loop through commands and add to glyph
while( i < end )
{
//System.out.println(i+" "+x+" "+y);
switch (commands[i]) {
case T1GlyphFactory.L:
elements.add(new LineTo(x[i],y[i]-ymin));
break;
case T1GlyphFactory.H:
elements.add( new ClosePath());
elements.add( new MoveTo(0,0));
break;
case T1GlyphFactory.M:
elements.add( new MoveTo(x[i], y[i]-ymin));
break;
case T1GlyphFactory.C:
elements.add(new CubicCurveTo(x[i], y[i]-ymin,
x2[i],y2[i]-ymin,
x3[i], y3[i]-ymin));
break;
default:
break;
}
i++;
}
return currentPath;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy