1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
/******************************************************************************
* program: wp2latex *
* function: module for conversion Accent files into LaTeX *
* modul: pass1acc.cc *
* description: This module contains parser for Accent documents. It could be *
* optionally compiled with WP2LaTeX package. *
* licency: GPL *
******************************************************************************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stringa.h>
#include<lists.h>
#include<dbllist.h>
#include"wp2latex.h"
#include"pass1xml.h"
#include "cp_lib/cptran.h"
/*Register translators here*/
class TconvertedPass1_Accent: public TconvertedPass1_XML
{
public:
virtual int Convert_first_pass(void);
};
TconvertedPass1 *Factory_Accent(void) {return new TconvertedPass1_Accent;}
FFormatTranslator FormatAccent("Accent",Factory_Accent);
#define AccentVersion "0.4"
static void AccentImage(TconvertedPass1_XML *cq)
{
#ifdef DEBUG
fprintf(cq->log,"\n#AccentImage() ");fflush(cq->log);
#endif
int i;
long len;
const char *TAG;
TBox Box;
if(length(cq->TAG_Args)<1) return;
TAG=cq->TAG_Args[0];
if(TAG==NULL) return;
if(strncmp(TAG,"GRAPHIC WMF",11)) return;
TAG+=11;
i=sscanf(TAG,"%ld",&len);
if(len<0 || i<1)
{
if(cq->err != NULL)
fprintf(cq->err,_("\nError: Length of embedded image is not specified!"));
return;
}
fseek(cq->wpd,len,SEEK_CUR); //Skip image - this might be improved
Box.Width = -1; // Undefined, use default 100mm
Box.Image_type=0; //Image on disk
Box.AnchorType = 0; /*0-Paragraph, 1-Page, 2-Character*/
Box.HorizontalPos=2; /*0-Left, 1-Right, 2-Center, 3-Full */
Box.Image_size=0;
ImageWP(cq, "dummy", Box);
}
static void ProcessKeyAccent(TconvertedPass1_XML *cq)
{
#ifdef DEBUG
fprintf(cq->log,"\n#ProcessKeyAccent() ");fflush(cq->log);
#endif
string TAG;
const char *tag;
BYTE by,subby;
*cq->ObjType=0;
if(cq->TAG.isEmpty()) cq->ReadXMLTag();
by=cq->by;
subby=cq->subby;
switch(by)
{
case XML_char:
switch(cq->subby) //Normal character
{
case 10:
case 13:by=128;break; //CR
case 9:strcpy(cq->ObjType, "!Tab");
case 32:by=32;break; //Space
}
break;
case XML_extchar:
if(cq->TAG.isEmpty()) break; //Extended chatacter &xxx;
TAG=Ext_chr_str(cq->TAG[0],cq)+copy(cq->TAG,1,length(cq->TAG)-1);
tag=TAG();
by=201;
break;
case XML_tag:
TAG = copy(cq->TAG,1,length(cq->TAG)-2); //Normal tag <xxx>
if((tag=TAG())==NULL) break;
if(TAG=="AC"){by=134;subby=0x82;break;} //Justification Center
if(TAG=="AJ"){by=134;subby=0x81;break;} //Justification Full
if(TAG=="AL"){by=134;subby=0x80;break;} //Justification Left
if(TAG=="AR"){by=134;subby=0x83;break;} //Justification Right
if(TAG=="B")
{
if(StrStr(cq->TAG_Args.Member(0,0),"/B"))
by=130;
else by=129;
subby=12;break;
} //ATTR on bold
if(TAG=="BIG") {by=129;subby=2;break;} //ATTR on large
if(TAG=="BR") {by=131;break;} //HRt
if(TAG=="DD") {by=140;break;} //Indented definition
if(TAG=="FLD") {by=145;break;} //Image
if(TAG=="H1") {by=135;subby=1;break;} //section level 1
if(TAG=="H2") {by=135;subby=2;break;} //section level 2
if(TAG=="H3") {by=135;subby=3;break;} //section level 3
if(TAG=="H4") {by=135;subby=4;break;} //section level 4
if(TAG=="H5") {by=135;subby=1;break;} //section level 5
if(TAG=="H6") {by=135;subby=2;break;} //section level 6
if(TAG=="HR") {by=139;subby=0;break;} //horizontal line
if(TAG=="I") //ATTR on italic
{
if(StrStr(cq->TAG_Args.Member(0,0),"/I"))
by=130;
else by=129;
subby=8;break;
}
if(TAG=="IMG") {by=142;break;} //Image
// if(TAG=="LI") {by=144;subby=2;break;} //Start of item
if(TAG=="META") {by=137;subby=0;break;} //meta tag
if(TAG=="P") {by=132;break;} //new paragraph
if(TAG=="S") //ATTR on strike out
{
if(StrStr(cq->TAG_Args.Member(0,0),"/S"))
by=130;
else by=129;
subby=13;break;
}
if(TAG=="SMALL"){by=129;subby=3;break;} //ATTR on small
if(TAG=="SCRIPT"){by=138;subby=0;break;} //start SCRIPT
if(TAG=="SUB") {by=129;subby=6;break;} //ATTR on subscript
if(TAG=="SUP") {by=129;subby=5;break;} //ATTR on superscript
if(TAG=="T") {by=143;subby=0;break;} //Start of the table
if(TAG=="TD") {by=143;subby=4;break;} //Start of cell
if(TAG=="TH") {by=143;subby=6;break;} //Start of head cell
if(TAG=="TR") {by=143;subby=2;break;} //Start of row
if(TAG=="TT") {by=129;subby=16;break;} //ATTR on typewriter
if(TAG=="U") //ATTR on underline
{
if(StrStr(cq->TAG_Args.Member(0,0),"/U"))
by=130;
else by=129;
subby=14;break;
}
// if(TAG=="UL") {by=144;subby=0;break;} //Start of itemize
break;
case XML_closetag:
TAG = copy(cq->TAG,2,length(cq->TAG)-3); //Closing tag </xxx>
if( (tag=TAG())==NULL) break;
if(TAG=="B") {by=130;subby=12;break;} //ATTR off bold
if(TAG=="BIG") {by=130;subby=2;break;} //ATTR off large
if(TAG=="DD") {by=141;break;} //End of indented definition
if(TAG=="DL") {by=141;break;} //End of definition list
if(TAG=="H1") {by=136;subby=1;break;} //section off level 1
if(TAG=="H2") {by=136;subby=2;break;} //section off level 2
if(TAG=="H3") {by=136;subby=3;break;} //section off level 3
if(TAG=="H4") {by=136;subby=4;break;} //section off level 4
if(TAG=="H5") {by=136;subby=1;break;} //section off level 5
if(TAG=="H6") {by=136;subby=2;break;} //section off level 6
// if(TAG=="LI") {by=144;subby=3;break;} //End of item
if(TAG=="I") {by=130;subby=8;break;} //ATTR off italic
if(TAG=="P") {by=133;break;} //end paragraph
if(TAG=="S") {by=130;subby=13;break;} //ATTR off strike out
if(TAG=="SMALL"){by=130;subby=3;break;} //ATTR off small
if(TAG=="SCRIPT"){by=138;subby=1;break;} //end SCRIPT
if(TAG=="SUB") {by=130;subby=6;break;} //ATTR off subscript
if(TAG=="SUP") {by=130;subby=5;break;} //ATTR off superscript
if(TAG=="T") {by=143;subby=1;break;} //End of Table
if(TAG=="TD") {by=143;subby=5;break;} //End of cell
if(TAG=="TH") {by=143;subby=7;break;} //End of head cell
if(TAG=="TR") {by=143;subby=3;break;} //End of row
if(TAG=="TT") {by=130;subby=16;break;} //ATTR off typewriter
if(TAG=="U") {by=130;subby=14;break;} //ATTR off underline
// if(TAG=="UL") {by=144;subby=1;break;} //End of itemize
break;
case XML_CDATA:
case XML_comment: //comment
break;
case XML_badextchar:
if(cq->TAG.isEmpty()) break; //Extended chatacter &xxx
cq->TAG[length(cq->TAG)-1]=' ';
TAG = Ext_chr_str(cq->TAG[0],cq)+copy(cq->TAG,1,length(cq->TAG)-1);
tag = TAG();
by = 201;
break;
}
cq->by=by;
cq->subby=subby;
if(cq->flag<Nothing)
switch(by)
{
case XML_char: //Normal character
tag = Ext_chr_str(subby,cq,cq->ConvertCpg);
CharacterStr(cq,tag);
break;
case XML_CDATA:
case XML_comment: //comment
cq->CommentXML();
break;
case XML_unicode:
CharacterStr(cq,cq->TAG);
break; //Already expanded unicode character
case 32:putc(' ', cq->strip); /*soft space*/
break;
case 128:if(cq->TablePos!=1 && cq->TablePos!=3)
if(cq->char_on_line)
SoftReturn(cq);
break;
case 129:AttrOn(cq->attr,subby);break;
case 130:AttrOff(cq,subby); break;
case 131:HardReturn(cq); break;
case 132:if(cq->char_on_line) HardReturn(cq); //Paragraph on
SoftReturn(cq);
break;
case 133:if(cq->char_on_line) HardReturn(cq); //Paragraph off
break;
case 134:Justification(cq,subby);break;
case 135:StartSection(cq,-subby);break;
case 136:EndSection(cq,-subby); break;
// case 137:MetaHTML(cq); break;
// case 138:ScriptXML(cq); break;
case 139:HLine(cq,-16); break;
// case 140:IndentHTML(cq); break;
case 141:End_of_indent(cq); break;
// case 142:ImageHTML(cq); break;
case 143:switch(subby)
{
// case 0:TableHTML(cq);cq->TablePos=1;break;
case 1:EndTable(cq);cq->TablePos=0; break;
case 2:RowTable(cq);cq->TablePos|=2;break;
case 3:cq->TablePos&=~2;break;
case 4:
case 6:CellTable(cq);cq->TablePos|=4;break;
case 5:
case 7:cq->TablePos&=~4;break;
}
break;
// case 144:switch(subby)
// {
// case 0:ItemizeHTML(cq);break;
// }
// break;
case 145:AccentImage(cq);break;
case 200:fputc('~', cq->strip);strcpy(cq->ObjType, " ");
break;
case 201:CharacterStr(cq,tag);break; //
}
cq->by=by;
cq->subby=subby;
if (cq->log != NULL)
{ /**/
if(by==128) fputc('\n',cq->log);
else if(by==' ' || by==200) fputc(' ',cq->log);
else if(by==0 || by==201)
{
fprintf(cq->log,"%s",tag);
}
else
{
fprintf(cq->log, _("\n%*s [%s %s] "),
cq->recursion * 2, "", cq->TAG(), cq->ObjType);
// if(*cq->ObjType==0) UnknownObjects++;
}
}
cq->ActualPos = ftell(cq->wpd);
}
int TconvertedPass1_Accent::Convert_first_pass(void)
{
#ifdef DEBUG
fprintf(log,"\n#TconvertedPass1_Accent::Convert_first_pass() ");fflush(log);
#endif
DWORD fsize;
if(Verbosing >= 1)
printf(_("\n>>>Accent2LaTeX<<< Conversion program: From Accent to LaTeX Version %s\n"
" Made by J.Fojtik (Hosted on WP2LaTeX :))))\n\n"),
AccentVersion);
ConvertHTML = GetTranslator("htmlTOinternal");
CharReader = &ch_fgetc;
TablePos=0;
DocumentStart = ftell(wpd);
fsize = FileSize(wpd);
perc.Init(ftell(wpd), fsize,_("First pass Accent:") );
ActualPos = ftell(wpd);
while (ActualPos < fsize)
{
if(Verbosing >= 1) //actualise a procentage counter
perc.Actualise(ActualPos);
TAG.erase();
ProcessKeyAccent(this);
}
Finalise_Conversion(this);
return(1);
}
|