All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.objects.raw.FontObject Maven / Gradle / Ivy

There is a newer version: 20151002
Show newest version
/*
 * ===========================================
 * 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


 *
 * ---------------
 * FontObject.java
 * ---------------
 */
package org.jpedal.objects.raw;

import org.jpedal.fonts.StandardFonts;
import org.jpedal.utils.LogWriter;

public class FontObject extends PdfObject {

    //mapped onto Type1
    private static final int MMType1=1230852645;

    //mapped onto Type1
    private static final int Type1C=1077224796;

    private static final int ZaDb=707859506;

    private static final int ZapfDingbats=1889256112;

    private static final int Symbol=1026712197;

    private PdfObject CharProcs, CIDSet, CIDSystemInfo, CIDToGIDMap,
    DescendantFonts,
    FontDescriptor,FontFile,
    FontFile2, FontFile3, ToUnicode;

    int BaseEncoding=PdfDictionary.Unknown;

	int CIDToGIDMapAsConstant=PdfDictionary.Unknown;

    int FirstChar,LastChar=255,Flags,MissingWidth,DW=-1,StemV, Supplement;

    float Ascent,Descent;

    float[] Widths,FontBBox;

    double[] FontMatrix;

    byte[][] Differences;
    
    Object[] W,W2;

    private byte[] rawBaseFont,rawCharSet, rawCMapName,
    rawFontName,rawFontStretch,
    rawOrdering, rawRegistry;

    private String BaseFont,CharSet, CMapName,
    FontName,FontStretch, Ordering,Registry;
    private int[] DW2;

    public FontObject(final String ref) {
        super(ref);
    }

    public FontObject(final int ref, final int gen) {
       super(ref,gen);
    }


    public FontObject(final int type) {
    	super(type);
	}

    @Override
    public PdfObject getDictionary(final int id){

        switch(id){

            case PdfDictionary.CharProcs:
                return CharProcs;

            case PdfDictionary.CIDSet:
                return CIDSet;

            case PdfDictionary.CIDSystemInfo:
	        	return CIDSystemInfo;

	        case PdfDictionary.CIDToGIDMap:
	        	return CIDToGIDMap;

            case PdfDictionary.DescendantFonts:
                return DescendantFonts;

            case PdfDictionary.Encoding:
                return Encoding;

            case PdfDictionary.FontDescriptor:
                return FontDescriptor;

            case PdfDictionary.FontFile:
                return FontFile;

            case PdfDictionary.FontFile2:
                return FontFile2;

            case PdfDictionary.FontFile3:
                return FontFile3;

            case PdfDictionary.ToUnicode:
                return ToUnicode;

            default:
                return super.getDictionary(id);
        }
    }

    @Override
    public void setIntNumber(final int id, final int value){

        switch(id){

            case PdfDictionary.Ascent:
                Ascent=value;
                break;

            case PdfDictionary.Descent:
                Descent=value;
                break;

	        case PdfDictionary.DW:
	            DW=value;
	        break;

            case PdfDictionary.FirstChar:
                FirstChar=value;
            break;

            case PdfDictionary.Flags:
                Flags=value;
            break;

            case PdfDictionary.LastChar:
                LastChar=value;
            break;

            case PdfDictionary.MissingWidth:
                MissingWidth=value;
            break;

            case PdfDictionary.StemV:
                StemV=value;
            break;

            case PdfDictionary.Supplement:
            	Supplement=value;
            break;

            default:
            	super.setIntNumber(id, value);
        }
    }

    @Override
    public int getInt(final int id){

        switch(id){

	        case PdfDictionary.DW:
	            return DW;

            case PdfDictionary.FirstChar:
                return FirstChar;

            case PdfDictionary.Flags:
                return Flags;

            case PdfDictionary.LastChar:
                return LastChar;

            case PdfDictionary.MissingWidth:
                return MissingWidth;

            case PdfDictionary.StemV:
                return StemV;

            case PdfDictionary.Supplement:
                return Supplement;

            default:
            	return super.getInt(id);
        }
    }

    @Override
    public void setFloatNumber(final int id, final float value){

        switch(id){

            case PdfDictionary.Ascent:
                Ascent=value;
                break;

            case PdfDictionary.Descent:
                Descent=value;
                break;

            default:
                super.setFloatNumber(id, value);
        }
    }

    @Override
    public float getFloatNumber(final int id){

        switch(id){

            case PdfDictionary.Ascent:
                return Ascent;

            case PdfDictionary.Descent:
                return Descent;

            default:
                return super.getFloatNumber(id);
        }
    }

    @Override
    public void setDictionary(final int id, final PdfObject value){

    	value.setID(id);

        //flag embedded data
        if(id==PdfDictionary.FontFile || id==PdfDictionary.FontFile2 || id==PdfDictionary.FontFile3) {
            hasStream = true;
        }


        switch(id){

            case PdfDictionary.CharProcs:
    		    CharProcs=value;
    		    break;

            case PdfDictionary.CIDSet:
                CIDSet=value;
                break;

            case PdfDictionary.CIDSystemInfo:
	        	CIDSystemInfo=value;
	        break;

	        case PdfDictionary.CIDToGIDMap:
	        	CIDToGIDMap=value;
            break;

            case PdfDictionary.DescendantFonts:
                DescendantFonts=value;
            break;

            case PdfDictionary.Encoding:
                Encoding=value;
            break;

            case PdfDictionary.FontDescriptor:
                FontDescriptor=value;
            break;

            case PdfDictionary.FontFile:
                FontFile=value;
            break;

            case PdfDictionary.FontFile2:
                FontFile2=value;
            break;

            case PdfDictionary.FontFile3:
                FontFile3=value;
            break;

            case PdfDictionary.ToUnicode:
            	ToUnicode=value;
            break;

            default:
            	super.setDictionary(id, value);
        }
    }


    @Override
    public int setConstant(final int pdfKeyType, final int keyStart, final int keyLength, final byte[] raw) {

        int PDFvalue =PdfDictionary.Unknown;

        int id=0,x=0,next;

        try{

            //convert token to unique key which we can lookup

            for(int i2=keyLength-1;i2>-1;i2--){

            	next=raw[keyStart+i2];

            	next -= 48;

                id += ((next)<6 && data[6]=='+'){ //lose ABCDEF+ if present
                		final int length=len-7;
                		final byte[] newData=new byte[length];
                		System.arraycopy(data, 7, newData, 0, length);
                		return new String(newData);
                    }else if(len>7 && data[len-7]=='+'){ //lose +ABCDEF if present
                        final int length=len-7;
                        final byte[] newData=new byte[length];
                        System.arraycopy(data, 0, newData, 0, length);
                        return new String(newData);
                    }else {
                        return new String(data);
                    }
                }else {
                    return null;
                }

            default:
                throw new RuntimeException("Value not defined in getName(int,mode)");
        }
    }

    @Override
    public int getObjectType() {
		return PdfDictionary.Font;
	}


    @Override
    public boolean decompressStreamWhenRead() {
		return true;
	}
   
    @Override
    public Object[] getObjectArray(final int id) {
        
        switch(id){
            
            case PdfDictionary.W:
                return W;                
                
            case PdfDictionary.W2:
                return W2; 
                
            default:    
                return super.getObjectArray(id);
        }
        
    }
    
    @Override
    public void setObjectArray(final int id, final Object[] objectValues) {
        
        switch(id){
            
            case PdfDictionary.W:
                
                W= objectValues;
                break;
                
            case PdfDictionary.W2:
                
                W2= objectValues;
                break;    
                
            default:
                super.setObjectArray(id, objectValues);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy