📄 main.cpp
字号:
/*****************************************************************************************
* Copyright (c) 2007 Hewlett-Packard Development Company, L.P.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************************/
/************************************************************************
* SVN MACROS
*
* $LastChangedDate: 2008-09-02 17:10:10 +0530 (Tue, 02 Sep 2008) $
* $Revision: 685 $
* $Author: mnab $
*
************************************************************************/
#include <stdio.h>
#include <iostream>
#include <fstream>
#include "LTKImageWriter.h"
#include "LTKStringUtil.h"
#include "Inc.h"
#define SUPPORTED_MIN_VERSION "2.1.0"
void startUp(string strRootDir,string strTempDir){
makedir(strTempDir.c_str());
DIR *rootDIR;
DIR *tempDIR;
struct dirent *tempDIREntry;
rootDIR=opendir(strRootDir.c_str());
if(rootDIR==NULL)
{
makedir(strRootDir.c_str());
makedir(strTempDir.c_str());
}
else
{
tempDIR=opendir(strTempDir.c_str());
if(tempDIR==NULL)
{
makedir(strTempDir.c_str());
}
closedir (tempDIR);
}
tempDIR=opendir(strTempDir.c_str());
readdir(tempDIR);
readdir(tempDIR);
while((tempDIREntry=readdir(tempDIR))!=NULL)
{
string eachFile(tempDIREntry->d_name);
string eachFilePath=strTempDir+"/"+eachFile;
remove(eachFilePath.c_str());
}
closedir (tempDIR);
closedir (rootDIR);
}
void writeImageFile(string srcFileName, string destFileName,
string dataFormat, string view,
unsigned char red, unsigned char green,
unsigned blue, int width, int height,
int size, bool bb, bool sp)
{
try
{
cout<<"Creating image "<<destFileName<<" for "<<srcFileName<<endl;
LTKImageWriter iw;
iw.setColor(red,green,blue);
int offset=0;
if(view=="original")
{
offset=0;
}
else if(view=="strokewise")
{
offset=1;
}
iw.setOffset(offset);
iw.showStartingPoint(sp);
if(dataFormat=="unipen")
{
if(bb)
{
if(size==0)
{
cout<<"size of dim cannot be zero while drawing the image with bounding box"<<endl;
exit(1);
}
iw.drawUnipenFileToImageWithBB(srcFileName.c_str(),destFileName.c_str(),size);
}
else
{
if(width==0 && height==0 && size==0)
{
iw.drawUnipenFileToImage(srcFileName.c_str(),destFileName.c_str());
}
else if(width==0 && height==0)
{
iw.drawUnipenFileToImage(srcFileName.c_str(),destFileName.c_str(),size);
}
else
{
iw.drawUnipenFileToImage(srcFileName.c_str(),destFileName.c_str(),width,height);
}
}
}
else if(dataFormat=="hpl")
{
if(width==0 && height==0 && size==0)
{
iw.drawRawInkFileToImage(srcFileName.c_str(),destFileName.c_str());
}
else if(width==0 && height==0)
{
iw.drawRawInkFileToImage(srcFileName.c_str(),destFileName.c_str(),size);
}
else
{
iw.drawRawInkFileToImage(srcFileName.c_str(),destFileName.c_str(),width,height);
}
}
}
catch(...)
{
cout<<"Unable to generate image for the file:"<<srcFileName<<endl;
}
}
void displayHelp()
{
cout<<endl;
cout<<" -----------------------------------------------------"<<endl
<<" | Options | Values |"<<endl
<<" |----------------------------------------------------"<<endl
<<" | -data | unipen OR hpl default=unipen |"<<endl
<<" | -view | original OR strokewise default=original |"<<endl
<<" | -show | on OR off default=on when set,displays |"<<endl
<<" | | in the browser |"<<endl
<<" | -file | path to the file containing list of ink |"<<endl
<<" | | files paths |"<<endl
<<" | -fext | extension of files for which images need|"<<endl
<<" | | to be generated default=.txt |"<<endl
<<" | -color | red,green,blue (each ranging from 0 to |"<<endl
<<" | | 255) default=0,0,0 |"<<endl
<<" | -dim | width,height OR size (size retains the |"<<endl
<<" | | aspect ratio) default=50,50 |"<<endl
<<" | -bb | true,false default=false when set,shows |"<<endl
<<" | | the bounding box |"<<endl
<<" | -sp | true,false default=false when set,shows |"<<endl
<<" | | the starting point of each stroke |"<<endl
<<" -----------------------------------------------------"<<endl
<<"1. The last 2 arguments are src and dest dir/file name. "<<endl
<<"2. If show is on, mention only the src dir/file name."<<endl
<<"3. If -file is set, images are generated in respective source directories."<<endl
<<"4. The -fext option is applicable only when source directory is mentioned."<<endl
<<"5. To write ink files as images, mention src & dest dir/file name."<<endl
<<"6. The extension of the destination image file should be \"bmp\"."<<endl<<endl
<<"Example:>> imgwriter -fext .new -view strokewise -color 0,255,255"<<endl
<<" -dim 100 -sp true c:/data/usr2"<<endl;
}
string getFileName(string filePath)
{
int forwardSlashIndex=filePath.find_last_of('/');
int backwardSlashIndex=filePath.find_last_of('\\');
int slashIndex;
if(forwardSlashIndex>backwardSlashIndex && forwardSlashIndex!=string::npos)
{
slashIndex=forwardSlashIndex;
slashIndex++;
}
else if(backwardSlashIndex!=string::npos)
{
slashIndex=backwardSlashIndex;
slashIndex++;
}
else{
slashIndex=0;
}
int dotIndex=filePath.find_last_of('.');
if(dotIndex==string::npos)
{
dotIndex=filePath.length();
}
string fileName=filePath.substr(slashIndex,(filePath.length()-slashIndex+1)-(filePath.length()-dotIndex+1));
return fileName;
}
int main(int argc,char *argv[]){
try{
string view="original"; //other value is strokewise
int colorR=0;
int colorG=0;
int colorB=0;
bool show=true;
int dimW=50;
int dimH=50;
int size=0;
string data="unipen"; //other value is hpl
bool bb=false; //bounding box
bool sp=false; //starting point
string src;
string dest;
string filesList;
string fileExt=".txt";
string existingTempDir(TEMPDIR);
string strRootDir=existingTempDir+"/marchtool";
string strTempDir=strRootDir+"/"+"mt_tmp";
//startUp(strRootDir,strTempDir);
if(argc==1)
{
displayHelp();
exit(1);
}
for(int i=1;i<argc;)
{
string arg(argv[i]);
if(arg=="-help")
{
displayHelp();
exit(1);
}
else if(arg=="-view")
{
i++;
string value(argv[i]);
if((value!="original" && value!="strokewise"))
{
cout<<"'"<<value<<"' not defined for view"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
else
{
view=value;
i++;
}
}
else if(arg=="-color")
{
i++;
string value(argv[i]);
vector<string> rgbVec;
LTKStringUtil::tokenizeString(value, ",", rgbVec);
if(rgbVec.size()!=3)
{
cout<<"'"<<value<<"' not defined for color"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
else
{
colorR=atoi(rgbVec[0].c_str());
if(colorR>255)
{
colorR=255;
}
else if(colorR<0)
{
colorR=0;
}
colorG=atoi(rgbVec[1].c_str());
if(colorG>255)
{
colorG=255;
}
else if(colorG<0)
{
colorG=0;
}
colorB=atoi(rgbVec[2].c_str());
if(colorB>255)
{
colorB=255;
}
else if(colorB<0)
{
colorB=0;
}
i++;
}
}
else if(arg=="-show")
{
i++;
string value(argv[i]);
if(value!="on" && value!="off")
{
cout<<"'"<<value<<"' not defined for show"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
else
{
if(value=="on")
{
show=true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -