org.jpedal.parser.gs.CM 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
Open Source (LGPL) JavaFX PDF Viewer for NetBeans plugin
/*
* ===========================================
* 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-2017 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
@LICENSE@
*
* ---------------
* CM.java
* ---------------
*/
package org.jpedal.parser.gs;
import org.jpedal.objects.GraphicsState;
import org.jpedal.parser.CommandParser;
import org.jpedal.utils.Matrix;
/**
*
*/
public class CM {
public static void execute(final GraphicsState gs, final CommandParser parser) {
//create temp Trm matrix to update Tm
final float[][] Trm = new float[3][3];
//set Tm matrix
Trm[0][0] = parser.parseFloat(5);
Trm[0][1] = parser.parseFloat(4);
Trm[0][2] = 0;
Trm[1][0] = parser.parseFloat(3);
Trm[1][1] = parser.parseFloat(2);
Trm[1][2] = 0;
Trm[2][0] = parser.parseFloat(1);
Trm[2][1] = parser.parseFloat(0);
Trm[2][2] = 1;
//copy last CM
for (int i = 0; i < 3; i++) {
System.arraycopy(gs.CTM, 0, gs.lastCTM, 0, 3);
}
//multiply to get new CTM
gs.CTM = Matrix.multiply(Trm, gs.CTM);
//remove slight sheer
//if(gs.CTM[0][0]>0 && gs.CTM[1][1]>0 && gs.CTM[1][0]>0 && ((gs.CTM[1][0]<0.01 && gs.CTM[0][1]<0) || (gs.CTM[0][0]>100 && gs.CTM[0][1]<2))){
//added for odd case with file upsidedownlogo.pdf
if (gs.CTM[0][0] > 0 && gs.CTM[1][1] > 0 && Math.abs(gs.CTM[0][1]) < 0.001 && gs.CTM[1][0] == 0) {
gs.CTM[0][1] = 0;
}
if (gs.CTM[0][0] > 0 && gs.CTM[1][1] > 0 && gs.CTM[1][0] > 0 && ((gs.CTM[1][0] < 0.01 && gs.CTM[0][1] < 0) || (gs.CTM[0][0] > 100 && gs.CTM[0][1] == gs.CTM[1][0] && gs.CTM[0][1] == 1))) {
gs.CTM[0][1] = 0;
gs.CTM[1][0] = 0;
}
//Ignore very minor skew
// if(Math.abs(gs.CTM[0][1]/gs.CTM[0][0])<0.006 && Math.abs(gs.CTM[1][0]/gs.CTM[1][1])<0.006){
// gs.CTM[0][1]=0;
// gs.CTM[1][0]=0;
// }
//deal with very minor rotation on page in 17780
if (gs.CTM[1][0] > 100 && gs.CTM[0][1] > 100 && gs.CTM[0][0] < 0.001 && Math.abs(gs.CTM[1][1]) < 0.001) {
gs.CTM[0][0] = 0;
gs.CTM[1][1] = 0;
}
}
}