![JAR search and dependency download from the Maven repository](/logo.png)
org.jpedal.fonts.tt.BaseTTGlyph 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-2015 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
*
* ---------------
* BaseTTGlyph.java
* ---------------
*/
package org.jpedal.fonts.tt;
import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.util.HashSet;
import javafx.scene.shape.Path;
import org.jpedal.color.PdfPaint;
import org.jpedal.fonts.glyph.PdfGlyph;
import org.jpedal.fonts.tt.hinting.TTVM;
import org.jpedal.utils.LogWriter;
import org.jpedal.utils.repositories.*;
public abstract class BaseTTGlyph {
/**paths for the letter, marked as transient so it wont be serialized */
transient Vector_Path paths=new Vector_Path(10);
protected boolean ttHintingRequired;
public static boolean useHinting = true;
protected boolean containsBrokenGlyfData;
protected short compMinX, compMinY, compMaxX, compMaxY;
protected short minX,minY,maxX,maxY;
protected int[] scaledX, scaledY;
protected int BPoint1, BPoint2;
protected final Vector_Int xtranslateValues=new Vector_Int(5);
protected final Vector_Int ytranslateValues=new Vector_Int(5);
protected final short leftSideBearing;
protected final Vector_Double xscaleValues=new Vector_Double(5);
protected final Vector_Double yscaleValues=new Vector_Double(5);
protected final Vector_Double scale01Values=new Vector_Double(5);
protected final Vector_Double scale10Values=new Vector_Double(5);
protected double xscale=1,yscale=1,scale01,scale10;
protected int[] instructions;
protected int xtranslate,ytranslate;
protected int currentInstructionDepth=Integer.MAX_VALUE;
protected final Vector_Object glyfX=new Vector_Object(5);
protected final Vector_Object glyfY=new Vector_Object(5);
protected final Vector_Object curves=new Vector_Object(5);
protected final Vector_Object contours=new Vector_Object(5);
protected final Vector_Int endPtIndices=new Vector_Int(5);
protected int contourCount;
protected float unitsPerEm=64;
public static boolean debug;
protected int glyphNumber = -1;
//used to track which glyf for complex glyph
protected int compCount=1;
protected boolean isComposite;
protected double pixelSize;
/**Variables used by the constructor**/
private static final HashSet testedFonts = new HashSet();
int BP1x=-1,BP2x=-1,BP1y=-1,BP2y=-1;
//Track translations for recursion
int existingXTranslate;
int existingYTranslate;
int depth;
static {
final String value = System.getProperty("org.jpedal.useTTFontHinting");
if (value != null) {
useHinting = value.equalsIgnoreCase("true");
}
}
public static boolean redecodePage;
boolean isHinted;
private TTVM vm;
private String baseFontName;
/**
* Hinted constructor
*/
public BaseTTGlyph(final Glyf currentGlyf, final FontFile2 glyfTable, final Hmtx currentHmtx, final int idx, final float unitsPerEm, final TTVM vm){
glyphNumber = idx+1;
isHinted=true;
//this.glyfName=glyfName;
//this.idx=idx;
this.leftSideBearing =currentHmtx.getLeftSideBearing(idx);
//this.advanceWidth = currentHmtx.getAdvanceWidth(idx);
this.unitsPerEm=unitsPerEm;
final int p=currentGlyf.getCharString(idx);
glyfTable.setPointer(p);
if(glyfTable.getBytesLeft()>4){
readGlyph(currentGlyf,glyfTable);
this.vm=vm;
//if(!useFX)
createGlyph(isHinted);
}
}
/**
* Unhinted constructor
*/
public BaseTTGlyph(final Glyf currentGlyf, final FontFile2 glyfTable, final Hmtx currentHmtx, final int idx, final float unitsPerEm, final String baseFontName){
//debug=idx==2246;
glyphNumber = idx+1;
// this.glyfName=glyfName;
//this.idx=idx;
this.leftSideBearing =currentHmtx.getLeftSideBearing(idx);
//this.advanceWidth = currentHmtx.getAdvanceWidth(idx);
this.unitsPerEm=unitsPerEm;
this.baseFontName=baseFontName;
final int p=currentGlyf.getCharString(idx);
glyfTable.setPointer(p);
if(glyfTable.getBytesLeft()>4){
readGlyph(currentGlyf,glyfTable);
//if(!useFX)
createGlyph(false);
}
}
void createGlyph(final boolean isHinted){
if(isHinted){
createHintedGlyph();
}else{
createUnhintedGlyph();
}
}
void createUnhintedGlyph() {
/**create glyphs the first time*/
for(int i=0;imaxX || minY>maxY){
return;
}
if(debug){
System.out.println("------------------------------------------------------------");
System.out.println("min="+minX+ ' ' +minY+" max="+maxX+' '+maxY+" contourCount="+contourCount);
}
if(contourCount!=65535){
if(contourCount>0){
readSimpleGlyph(currentFontFile);
}
}else{
compMinX=minX;
compMinY=minY;
compMaxX=maxX;
compMaxY=maxY;
if(debug) {
System.out.println("XXmain=" + minX + ' ' + minY + ' ' + maxX + ' ' + maxY);
}
readComplexGlyph(currentGlyf,currentFontFile);
}
}
/**
* @return Whether the font requires hinting in order to correctly arrange its subglyphs
*/
public boolean isTTHintingRequired(){
return ttHintingRequired;
}
public void createPaths(final int[] pX, final int[] pY, final boolean[] onCurve, final boolean[] endOfContour, final int endIndex) {
throw new UnsupportedOperationException("createPaths Not supported yet.");
}
void clearPaths() {
throw new UnsupportedOperationException("clearPaths Not supported yet.");
}
public void render(final int text_fill_type, final Graphics2D g2, final float scaling, final boolean isFormGlyph) {
throw new UnsupportedOperationException("render Not supported yet.");
}
public void setWidth(final float width) {
}
public int getFontBB(final int type) {
if(isComposite){
if(type== PdfGlyph.FontBB_X) {
return compMinX;
} else if(type== PdfGlyph.FontBB_Y) {
return compMinY;
} else if(type== PdfGlyph.FontBB_WIDTH) {
return compMaxX;
} else if(type== PdfGlyph.FontBB_HEIGHT) {
return compMaxY;
} else {
return 0;
}
}else{
if(type== PdfGlyph.FontBB_X) {
return minX;
} else if(type== PdfGlyph.FontBB_Y) {
return minY;
} else if(type== PdfGlyph.FontBB_WIDTH) {
return maxX;
} else if(type== PdfGlyph.FontBB_HEIGHT) {
return maxY;
} else {
return 0;
}
}
}
public void setStrokedOnly(final boolean b) {
//not used here
}
//use by TT to handle broken TT fonts
public boolean containsBrokenData() {
return this.containsBrokenGlyfData;
}
public Path getPath() {
throw new UnsupportedOperationException("getPath Not supported yet.");
}
public int getGlyphNumber() {
return glyphNumber;
}
public void setGlyphNumber(final int no) {
glyphNumber = no;
}
public Area getShape() {
throw new UnsupportedOperationException("getShape Not supported yet.");
}
void createHintedGlyph() {
/**create glyphs the first time*/
for(int i=0;i© 2015 - 2025 Weber Informatics LLC | Privacy Policy