summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/convwatch/PRNCompare.java
diff options
context:
space:
mode:
Diffstat (limited to 'qadevOOo/runner/convwatch/PRNCompare.java')
-rw-r--r--qadevOOo/runner/convwatch/PRNCompare.java184
1 files changed, 92 insertions, 92 deletions
diff --git a/qadevOOo/runner/convwatch/PRNCompare.java b/qadevOOo/runner/convwatch/PRNCompare.java
index 1d0503299d67..5c3f3f15dd82 100644
--- a/qadevOOo/runner/convwatch/PRNCompare.java
+++ b/qadevOOo/runner/convwatch/PRNCompare.java
@@ -1,7 +1,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -44,13 +44,13 @@ import util.utils;
// {
// final static int NO_DIFFERENCE = 1;
// final static int DIFFERENCE = 2;
-//
+//
// public int nValue = NO_DIFFERENCE;
// public boolean equals(int _n)
// {
// if ( _n == nValue ) return true;
// return false;
-// }
+// }
// }
// -----------------------------------------------------------------------------
@@ -63,7 +63,7 @@ public class PRNCompare
{
// m_aHelper = new OSHelper();
fs = System.getProperty("file.separator");
- }
+ }
String executeSynchronously(String _sCommand)
{
@@ -73,7 +73,7 @@ public class PRNCompare
boolean bBackValue = aHandler.executeSynchronously();
String sText = aHandler.getOutputText();
-
+
GlobalLogWriter.get().println("Exitcode: " + String.valueOf(aHandler.getExitCode()));
return sText;
}
@@ -81,7 +81,7 @@ public class PRNCompare
int getMaxNumOfFileEntry(String _sDirectory, String _sBasename)
{
-// TODO: check if directory exist should be done earlier
+// TODO: check if directory exist should be done earlier
File aDirectory = new File(_sDirectory);
File[] aDirList = aDirectory.listFiles(
/*
@@ -94,7 +94,7 @@ public class PRNCompare
}
} */
);
-
+
int nMaxNumber = 0;
for(int n = 0; n<aDirList.length ; n++)
{
@@ -102,7 +102,7 @@ public class PRNCompare
if (sDirEntry.endsWith(".jpg"))
{
int nNum = nMaxNumber;
-
+
if (sDirEntry.startsWith(_sBasename))
{
// System.out.println(sDirEntry);
@@ -116,11 +116,11 @@ public class PRNCompare
catch(java.lang.NumberFormatException e)
{
}
-
+
// System.out.println(nValue);
nNum = nValue;
}
-
+
if (nNum > nMaxNumber)
{
nMaxNumber = nNum;
@@ -129,7 +129,7 @@ public class PRNCompare
}
return nMaxNumber;
}
-
+
String m_sInputPath;
String m_sReferencePath;
String m_sOutputPath;
@@ -143,9 +143,9 @@ public class PRNCompare
String m_sDocumentType;
public void setInputPath(String _sInputPath) { m_sInputPath = _sInputPath; }
-
+
public void setReferencePath(String _sReferencePath) { m_sReferencePath = _sReferencePath; }
-
+
public void setOutputPath(String _sOutPath) { m_sOutputPath = _sOutPath; }
public void setDocFile(String _sDocFile) { m_sDocFile = _sDocFile;}
@@ -170,15 +170,15 @@ public class PRNCompare
{
m_sDocumentType = _sTypeName;
}
-
+
// -----------------------------------------------------------------------------
-
+
public StatusHelper[] compare()
{
createJPEGFromPostscript(m_sOutputPath, m_sReferencePath, m_sReferenceFile, getResolutionInDPI());
-// TODO: Assume, that Postscript is already in the OutputPath, this may change.
+// TODO: Assume, that Postscript is already in the OutputPath, this may change.
createJPEGFromPostscript(m_sOutputPath, m_sOutputPath, m_sPostScriptFile, getResolutionInDPI());
- StatusHelper[] aList = createDiffs(m_sOutputPath,
+ StatusHelper[] aList = createDiffs(m_sOutputPath,
m_sOutputPath, m_sReferenceFile,
m_sOutputPath, m_sPostScriptFile,
getMaxPages(), m_tUseBorderMove);
@@ -191,9 +191,9 @@ public class PRNCompare
public StatusHelper[] compare_new()
{
String[] aRefList = createJPEGFromPostscript(m_sOutputPath, m_sReferencePath, m_sReferenceFile, getResolutionInDPI());
-// TODO: Assume, that Postscript is already in the OutputPath, this may change.
+// TODO: Assume, that Postscript is already in the OutputPath, this may change.
String[] aPSList = createJPEGFromPostscript(m_sOutputPath, m_sOutputPath, m_sPostScriptFile, getResolutionInDPI());
- StatusHelper[] aList = createDiffs(m_sOutputPath,
+ StatusHelper[] aList = createDiffs(m_sOutputPath,
aRefList,
aPSList,
getMaxPages(), m_tUseBorderMove);
@@ -204,15 +204,15 @@ public class PRNCompare
static String getJPEGName(String _sOutputPath, String _sBasename, String _sGS_PageOutput)
{
String fs = System.getProperty("file.separator");
-
+
String sJPEGName = _sOutputPath + fs + _sBasename + _sGS_PageOutput + ".jpg";
return sJPEGName;
}
-
+
/**
* Create via ghostscript (gs) from the reference file for every page a JPEG file
*
- * MUST set:
+ * MUST set:
* m_sOutputPath, m_sReferenceFile, m_sReferencePath
*
* return exit code from gs command
@@ -224,7 +224,7 @@ public class PRNCompare
// {
// sGS_PageOutput = "%%d";
// }
-
+
FileHelper.makeDirectories("", _sOutputPath);
// create a jpeg from original prn
@@ -238,9 +238,9 @@ public class PRNCompare
{
sGS = "gswin32c.exe";
}
-
+
sCommand = sGS + " -dNOPROMPT -dBATCH -sDEVICE=jpeg -r" + String.valueOf(_nResolutionInDPI) + " -dNOPAUSE -sOutputFile=" + StringHelper.doubleQuoteIfNeed(sJPGFilename) + " " + StringHelper.doubleQuoteIfNeed(sOriginalFile);
- String[] sCommandArray =
+ String[] sCommandArray =
{
sGS,
"-dNOPROMPT",
@@ -259,11 +259,11 @@ public class PRNCompare
// System.out.println("FAILED");
// }
// System.out.println("done");
-
+
ProcessHandler aHandler = new ProcessHandler(sCommandArray);
boolean bBackValue = aHandler.executeSynchronously();
- // TODO: return a real filename, due to the fact we don't know how much files are created, maybe better to return a list
+ // TODO: return a real filename, due to the fact we don't know how much files are created, maybe better to return a list
ArrayList m_aFileList = new ArrayList();
for (int i=1;i<9999;i++)
@@ -282,7 +282,7 @@ public class PRNCompare
aList = (String[])m_aFileList.toArray(aList);
return aList; // sNewJPEGFilename;
}
-
+
/**
* Create Difference Files from the JPEGs
* parameter, how much difference files should create
@@ -297,10 +297,10 @@ public class PRNCompare
{
_nMaxDiffs = 1;
}
-
+
String sS1Basename = FileHelper.getBasename(_sSourceFile1);
String sS2Basename = FileHelper.getBasename(_sSourceFile2);
-
+
// count, from which file (jpegs) exist more, take the less one
// more are not compareable
int nS1_Files = getMaxNumOfFileEntry(_sSourcePath1, sS1Basename);
@@ -314,8 +314,8 @@ public class PRNCompare
nMin = Math.min(nMin, _nMaxDiffs);
StatusHelper[] aList = new StatusHelper[nMin];
-
-// TODO: if both document do not have same page count, produce an error
+
+// TODO: if both document do not have same page count, produce an error
// System.out.println("min of both: " + String.valueOf(nMin));
int nStatusIndex = 0;
@@ -325,10 +325,10 @@ public class PRNCompare
String sNewGfx = getJPEGName(_sSourcePath2, sS2Basename, StringHelper.createValueString(i, 4));
String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
-
+
String sDiffGfx = compareJPEGs(sOldGfx, sNewGfx, sDiffGfx_);
StatusHelper aStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
-
+
// if (FileHelper.exists(sDiffGfx))
if (sDiffGfx.length() > 0)
{
@@ -340,7 +340,7 @@ public class PRNCompare
else
{
try
- {
+ {
int nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
aStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
aStatus.nPercent = nPercent;
@@ -348,15 +348,15 @@ public class PRNCompare
// GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
// GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
// GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
-
+
// TODO: insert here the new BorderRemover if the percentage value is creater than 75%
- if (nPercent > 75 &&
+ if (nPercent > 75 &&
((_tUseBorderMove == TriState.TRUE ) ||
((_tUseBorderMove == TriState.UNSET) &&
m_sDocumentType.indexOf("MS PowerPoint") > 0)))
{
setBorderMove(TriState.TRUE);
-
+
String sOld_BM_Gfx = getJPEGName(_sSourcePath1, sS1Basename + ".BM", StringHelper.createValueString(i, 4));
String sNew_BM_Gfx = getJPEGName(_sSourcePath2, sS2Basename + ".BM", StringHelper.createValueString(i, 4));
String sDiff_BM_Gfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff.BM", StringHelper.createValueString(i, 4));
@@ -366,9 +366,9 @@ public class PRNCompare
BorderRemover a = new BorderRemover();
a.createNewImageWithoutBorder(sOldGfx, sOld_BM_Gfx);
a.createNewImageWithoutBorder(sNewGfx, sNew_BM_Gfx);
-
+
String sDiff_BM_Gfx = compareJPEGs( sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx_);
-
+
// if (FileHelper.exists(sDiff_BM_Gfx))
if (sDiff_BM_Gfx.length() > 0)
{
@@ -394,7 +394,7 @@ public class PRNCompare
GlobalLogWriter.get().println("Exception caught. At border remove: " + e.getMessage());
}
}
-
+
}
catch (java.io.IOException e)
@@ -402,9 +402,9 @@ public class PRNCompare
GlobalLogWriter.get().println(e.getMessage());
}
}
-
+
// checkDiff(sOldGfx, sNewGfx, sDiffGfx);
- // if (i >= _nMaxDiffs)
+ // if (i >= _nMaxDiffs)
// {
// break;
// }
@@ -413,7 +413,7 @@ public class PRNCompare
}
return aList;
}
-
+
public StatusHelper[] createDiffs(String _sOutputPath, String[] _aRefList, String[] _aPSList, int _nMaxDiffs, TriState _tUseBorderMove)
{
@@ -421,7 +421,7 @@ public class PRNCompare
{
_nMaxDiffs = 1;
}
-
+
// count, from which file (jpegs) exist more, take the less one
// more are not compareable
@@ -430,8 +430,8 @@ public class PRNCompare
nMin = Math.min(nMin, _nMaxDiffs);
StatusHelper[] aList = new StatusHelper[nMin];
-
-// TODO: if both document do not have same page count, produce an error
+
+// TODO: if both document do not have same page count, produce an error
// System.out.println("min of both: " + String.valueOf(nMin));
int nStatusIndex = 0;
@@ -444,7 +444,7 @@ public class PRNCompare
String sDiffGfx = compareJPEGs(sOldGfx, sNewGfx );
StatusHelper aStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
-
+
// if (FileHelper.exists(sDiffGfx))
if (sDiffGfx.length() > 0)
{
@@ -456,28 +456,28 @@ public class PRNCompare
else
{
try
- {
+ {
int nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
// GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
// GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
// GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
-
+
aStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
aStatus.nPercent = nPercent;
-
- if (nPercent > 75 &&
+
+ if (nPercent > 75 &&
((_tUseBorderMove == TriState.TRUE ) ||
((_tUseBorderMove == TriState.UNSET) &&
m_sDocumentType.indexOf("MS PowerPoint") > 0)))
{
_tUseBorderMove = TriState.TRUE;
-// TODO: problem is here, that we have to create some new names.
+// TODO: problem is here, that we have to create some new names.
String sBasename1 = FileHelper.getBasename(sOldGfx);
String sNameNoSuffix1 = FileHelper.getNameNoSuffix(sBasename1);
String sBasename2 = FileHelper.getBasename(sNewGfx);
String sNameNoSuffix2 = FileHelper.getNameNoSuffix(sBasename2);
-
+
String sTmpDir = util.utils.getUsersTempDir();
String fs = System.getProperty("file.separator");
@@ -488,11 +488,11 @@ public class PRNCompare
BorderRemover a = new BorderRemover();
a.createNewImageWithoutBorder(sOldGfx, sOld_BM_Gfx);
a.createNewImageWithoutBorder(sNewGfx, sNew_BM_Gfx);
-
+
String sDiff_BM_Gfx = compareJPEGs( sOld_BM_Gfx, sNew_BM_Gfx );
-
+
aStatus.setFilesForBorderMove(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
-
+
// if (FileHelper.exists(sDiff_BM_Gfx))
if (sDiff_BM_Gfx.length() > 0)
{
@@ -524,9 +524,9 @@ public class PRNCompare
GlobalLogWriter.get().println(e.getMessage());
}
}
-
+
// checkDiff(sOldGfx, sNewGfx, sDiffGfx);
- // if (i >= _nMaxDiffs)
+ // if (i >= _nMaxDiffs)
// {
// break;
// }
@@ -535,7 +535,7 @@ public class PRNCompare
}
return aList;
}
-
+
public static String compareJPEGs(String _sOldGfx, String _sNewGfx)
{
String sBasename1 = FileHelper.getBasename(_sOldGfx);
@@ -547,10 +547,10 @@ public class PRNCompare
String fs = System.getProperty("file.separator");
String sDiffName = sTmpDir + fs + sNameNoSuffix1 + "-" + sNameNoSuffix2 + "-diff.jpg";
-
+
return compareJPEGs(_sOldGfx, _sNewGfx, sDiffName);
}
-
+
public static String compareJPEGs(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
{
String sComposite = "composite";
@@ -558,13 +558,13 @@ public class PRNCompare
{
sComposite = "composite.exe";
}
-
- // String sCommand = sComposite + " -compose difference " +
+
+ // String sCommand = sComposite + " -compose difference " +
// StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
// StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
// StringHelper.doubleQuoteIfNeed(_sDiffGfx);
- String[] sCommandArray =
+ String[] sCommandArray =
{
sComposite,
"-compose",
@@ -573,9 +573,9 @@ public class PRNCompare
_sNewGfx,
_sDiffGfx
};
-
+
ProcessHandler aHandler = new ProcessHandler(sCommandArray);
- boolean bBackValue = aHandler.executeSynchronously();
+ boolean bBackValue = aHandler.executeSynchronously();
String sBack = aHandler.getOutputText();
GlobalLogWriter.get().println("'" + sBack + "'");
@@ -587,7 +587,7 @@ public class PRNCompare
}
return "";
}
-
+
/**
* wrapper for ImageMagick identify,
* function checks how many different colors a picture contains.
@@ -602,13 +602,13 @@ public class PRNCompare
// {
// sIM_Format = "%%k";
// }
-
+
String sIdentify = "identify";
if (OSHelper.isWindows())
{
sIdentify = "identify.exe";
}
-
+
// String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
String[] sCommandArray =
@@ -631,7 +631,7 @@ public class PRNCompare
{
sBack = sBack.substring(0, nIdx);
}
-
+
nResult = Integer.valueOf(sBack).intValue();
}
catch(java.lang.NumberFormatException e)
@@ -641,22 +641,22 @@ public class PRNCompare
}
return nResult;
}
-
+
/*
* Check 2 different differ files
* return 1 if there is no difference between both diff files.
*/
-// TODO: Maybe a StatusHelper is a better return value
+// TODO: Maybe a StatusHelper is a better return value
public StatusHelper checkDiffDiff(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2)
{
String sNewGfx = _sSourcePath1 + fs + _sSourceFile1;
String sOldGfx = _sSourcePath2 + fs + _sSourceFile2;
-
+
int nNumber = 1;
String sDiffGfx;
sDiffGfx = getJPEGName(_sOutputPath, _sSourceFile1 + ".diff", StringHelper.createValueString(nNumber, 4));
-
+
StatusHelper aCurrentStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
// String sComposite = "composite";
@@ -664,20 +664,20 @@ public class PRNCompare
// {
// sComposite = "composite.exe";
// }
- //
- // String sCommand = sComposite +" -compose difference " +
+ //
+ // String sCommand = sComposite +" -compose difference " +
// StringHelper.doubleQuoteIfNeed(sOldGfx) + " " +
// StringHelper.doubleQuoteIfNeed(sNewGfx) + " " +
// StringHelper.doubleQuoteIfNeed(sDiffGfx);
- //
- //
+ //
+ //
// // System.out.println(sCommand);
// // executeSynchronously(sCommand);
// ProcessHandler aHandler = new ProcessHandler(sCommand);
// boolean bBackValue = aHandler.executeSynchronously();
compareJPEGs(sOldGfx, sNewGfx, sDiffGfx);
-
+
if (FileHelper.exists(sDiffGfx))
{
int nResult = identify(sDiffGfx);
@@ -709,7 +709,7 @@ public class PRNCompare
return aCurrentStatus;
}
-
+
// -----------------------------------------------------------------------------
/**
* count how much pixel differ and between Old or New and the Difference graphics
@@ -727,9 +727,9 @@ public class PRNCompare
* text like outlined or the text is little bit move left, right up or down.
*
* >100% Yes it's possible that there is a difference more then 100%, maybe a font problem
- * between old and new graphics. The font of the new graphics is little bit bigger,
+ * between old and new graphics. The font of the new graphics is little bit bigger,
* so the pixel count between old graphics and new graphics is twice the more.
- *
+ *
*/
public int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
throws java.io.IOException
@@ -738,9 +738,9 @@ public class PRNCompare
int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx);
int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx);
int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx);
-
+
int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
-
+
// check if not zero
if (nMinNotWhiteCount == 0)
{
@@ -750,15 +750,15 @@ public class PRNCompare
nMinNotWhiteCount = 1;
}
}
-
+
int nPercent = Math.abs(nNotBlackCount_DiffGraphic * 100 / nMinNotWhiteCount);
GlobalLogWriter.get().println( "Graphics check, pixel based:" + String.valueOf(nPercent) + "% pixel differ ");
return nPercent;
}
+
-
-
-/*
+
+/*
* Some selftest functionallity
*/
// public static void main(String[] args)
@@ -781,10 +781,10 @@ public class PRNCompare
// LLA: 20040804 sample how to build jpegs from reference files
// a.createJPEGFromPostscript("/tmp/convwatch_java",
// "/home/apitest/WorkFromHome/20040804/reference", "worddoc.prn" );
-//
+//
// a.createJPEGFromPostscript("/tmp/convwatch_java",
// "/home/apitest/WorkFromHome/20040804/reference", "worddoc.ps" );
-
+
// Status[] aList = a.createDiffs("/tmp/convwatch_java",
// "/tmp/convwatch_java", "worddoc.prn",
// "/tmp/convwatch_java", "worddoc.ps",
@@ -799,7 +799,7 @@ public class PRNCompare
// {
// System.out.println("There is no difference between both diff files.");
// }
-
+
// a.setOldDiff( "/olddiffs");
// }
}