The htfcss records are stored in the following linked list, and used when the font entries ‘Font(”key”,”...”,”...”,”...”)’ are loaded (Section ’Contributions to Fonts’).
<..vars..>+
static struct htf_struct *htf_rec = (struct htf_struct *) 0;
-_-_-
<..defines..>+
struct htf_struct{
Q_CHAR *key, *body, *media;
struct htf_struct *next;
};
-_-_-
<..htfcss from lg..>
{ struct htf_struct *last_rec, *p;
last_rec = (struct htf_struct *) 0;
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("htfcss: ", TRUE, lg_file);
status = scan_until_end_str("", 1, status, lg_file);
<.remove leading spaces.>
if( status ){ Q_CHAR *key, *body, *media;
media = body = key = match[1];
<.process htfcss line.>
} }
}
-_-_-
<..remove leading spaces..>
if( status ){
Q_CHAR *s, *t;
int i;
s = t = match[1];
for( i=0; *s == ’ ’; s++ ) { i++; }
if( i>0 ){
while( *s != 0 ){
*(t++) = *(s++);
}
*t = 0;
} }
-_-_-
?? How the case ‘append prev htfcss rec’ can be reached ??
<..process htfcss line..>
while( *body && (*body != ’ ’) ){ body++; }
if( *body == ’ ’ ){ media = body; *(body++) = ’\0’; }
<.extract media info.>
if( *body ){
if( *key ){ <.add new htfcss rec.> }
#if 0 /* unreachable */
else if( last_rec ){ <.append prev htfcss rec.> }
#endif /* 0, unreachable */
}
-_-_-
<..extract media info..>
if( (int) strlen((char *) body) > 6 ){
if( (*(body) == ’@’)
&& (*(body+1) == ’m’)
&& (*(body+2) == ’e’)
&& (*(body+3) == ’d’)
&& (*(body+4) == ’i’)
&& (*(body+5) == ’a’) )
{
body += 6;
while( *body == ’ ’ ){ body++; }
media = body;
while( (*body != ’ ’) && (*body != ’\0’) ){ body++; }
if( *body == ’ ’ ){ *(body++) = ’\0’; }
while( *body == ’ ’ ){ body++; }
} }
-_-_-
<..add new htfcss rec..>
p = m_alloc(struct htf_struct, 1);
p->next = (struct htf_struct *) 0;
p->key = m_alloc(char, (int) strlen((char *) key) + 1);
(IGNORED) strcpy((char *) p->key, (char *) key );
p->media = m_alloc(char, (int) strlen((char *) media) + 1);
(IGNORED) strcpy((char *) p->media, (char *) media );
p->body = m_alloc(char, (int) strlen((char *) body) + 1);
(IGNORED) strcpy((char *) p->body, (char *) body );
if( last_rec ){
last_rec->next = p; last_rec = p;
} else {
htf_rec = last_rec = p;
}
if( debug ){
(IGNORED) printf(".......%s...%s...%s\n", key, media, body);
}
-_-_-
<..append prev htfcss rec..>
last_rec->body = (Q_CHAR *) r_alloc((void *) last_rec->body,
(size_t) strlen((char *) last_rec->body)
+ (size_t) strlen((char *) body)
+ 2);
(IGNORED) strct(last_rec->body,"\n");
(IGNORED) strct(last_rec->body,body);
if( debug ){
(IGNORED) printf(".......%s\n", body);
}
-_-_-
The command ‘\Configure{htf-css}{cmmi}{font-style: italic;}’ provides in the lg file an entry of the form ‘Font_Css_Plus cmmi font-style: italic;’.
<..font=(...) from lg..>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Font_Css_Plus ", TRUE, lg_file);
status = scan_until_str(" ", 1, status, lg_file);
status = scan_until_end_str("", 2, status, lg_file);
if( status ){ Q_CHAR *key;
key = match[1];
*(key + (int) strlen((char *) key) - 1) = ’\0’;
<.store font style of lg.>
} }
-_-_-
<..store font style of lg..>
if( (*key != ’\0’) && (*key != ’\n’) ) {
struct htf_struct *p;
p = m_alloc(struct htf_struct, 1);
p->next = htf_rec;
htf_rec = p;
p->key = m_alloc(char, (int) strlen((char *) key) + 1);
(IGNORED) strcpy((char *) p->key, (char *) key );
p->body = m_alloc(char, (int) strlen((char *) match[2]) + 1);
(IGNORED) strcpy((char *) p->body, (char *) match[2] );
if( debug ){
(IGNORED) printf(".......%s...%s\n", key, match[2]);
} }
-_-_-
<..process css..>
{
Q_CHAR css_name[255];
FILE *css_file, *tmp_file;
BOOL css_sty;
<.css-file = open file ....>
if( css_file ){
(IGNORED) printf ("Entering %s\n", css_name);
tmp_file = fopen(tmp_name, WRITE_TEXT_FLAGS);
if( !tmp_file ) {
(IGNORED) warn_i_str(5,tmp_name);
} else { <.c: tex4ht.tmp := css file.> }
tmp_file = open_file(tmp_name, ".tmp");
css_file = fopen(css_name, WRITE_TEXT_FLAGS);
if( !tmp_file ) {
(IGNORED) warn_i_str(5,tmp_name);
} else if( !css_file ) {
(IGNORED) warn_i_str(5,css_name);
} else {
<.c: css file = header of tex4ht.tmp.>
if( css_sty ){
<.css file = css.sty.>
<.css file = tail of tex4ht.tmp.>
}
}
(IGNORED) fclose(tmp_file);
(IGNORED) fclose(css_file);
} }
-_-_-
<..c: tex4ht.tmp := css file..>
int ch;
while( (ch = getc(css_file)) != EOF ) {
(IGNORED) putc( ch, tmp_file );
}
(IGNORED) fclose(tmp_file);
(IGNORED) fclose(css_file);
-_-_-
<..css-file = open file .....>
(IGNORED) strcpy((char *) css_name, (char *) job_name);
(IGNORED) strct(css_name, ".css");
css_file = fopen(css_name, READ_TEXT_FLAGS);
-_-_-
Copy until insertion point:
‘/* css.sty */’
<..c: css file = header of tex4ht.tmp..>
css_sty = FALSE;
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_until_end_str("", 1, TRUE, tmp_file);
<.match[2] := compressed match[1].>
if( eq_str(match[2], "/*css.sty*/") ){ css_sty = TRUE; break; }
(IGNORED) fprintf(css_file, "%s\n", match[1]);
}
-_-_-
<..vars..>+
static BOOL status;
-_-_-
<..match[2] := compressed match[1]..>
{ Q_CHAR *p, *q;
int n;
n = 0; p = match[1]; q = match[2];
while ( (*p != ’\0’) ){
if (n == 13) { *(q-10) = ’\0’; break;}
if( *p != ’ ’ ){ *(q++) = *p; n++; }
p++;
}
*q = ’\0’;
}
-_-_-
Contribution from lg File
<..css file = css.sty..>
(IGNORED) fprintf(css_file, "/* start css.sty */\n");
<.rewind lg file.> <.Font_css_base: ....>
<.rewind lg file.> <.process Font_Size: ....>
<.rewind lg file.> <.process Font(...).>
<.rewind lg file.> <.process Font_Css(...):....>
<.rewind lg file.> <.process Css:....>
(IGNORED) fprintf(css_file, "/* end css.sty */\n");
-_-_-
The ‘<process Css:...>’ should be after the other two’s to allow the user to overide with \Css commands the other contributions.
We want to remove the non-leading ‘/* css.sty */’, just in case t4ht.perl is called consequtively more than once.
<..css file = tail of tex4ht.tmp..>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_until_end_str("", 1, TRUE, tmp_file);
<.match[2] := compressed match[1].>
if( !eq_str(match[2], "/*css.sty*/") ){
(IGNORED) fprintf(css_file, "%s\n", match[1]);
}
}
-_-_-
‘Css: P.noindent { text-indent: 0em }’
<..process Css:.....>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Css: ", TRUE, lg_file);
status = scan_until_end_str("", 1, status, lg_file);
if( status ){
(IGNORED) fprintf(css_file, "%s\n", match[1]);
} }
-_-_-
‘\Needs{"Font_Size: 12"}’
<..process Font_Size: .....>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Font_Size: ", TRUE, lg_file);
status = scan_until_end_str("", 1, status, lg_file);
if( status ){
base_font_size = (int) get_long_int(match[1]);
} }
-_-_-
‘Font("family_name", "font_size", "design_sz * 100 / 655360 / 10", "mag")’ (e.g., ‘Font("cmr","10","10","100")’, ‘Font("aptmri","8t",??,"100")’, ‘Font("ecti","1095","10","100")’)
<..process Font(...)..>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Font(\"", TRUE, lg_file);
status = scan_until_str("\",\"", 1, status, lg_file);
status = scan_until_str("\",\"", 2, status, lg_file);
status = scan_until_str("\",\"", 3, status, lg_file);
status = scan_until_end_str("\")", 4, status, lg_file);
if( status ){
Q_CHAR *p;
struct htf_struct *font_sty;
int second;
p = match[1];
*(p + (int) strlen((char *) p) - 3) = ’\0’;
p = match[2];
*(p + (int) strlen((char *) p) - 3) = ’\0’;
p = match[3];
*(p + (int) strlen((char *) p) - 3) = ’\0’;
p = match[4];
*(p + (int) strlen((char *) p) - 2) = ’\0’;
<.get font size.>
<.get font style.>
} }
-_-_-
<..get font style..>
font_sty = htf_rec;
while ( font_sty ) {
if( eq_str(font_sty->key,match[1]) ){
if( *(font_sty->media) == ’\0’ ){
<.print font style css.>
second = 100;
} else {
<.print media style.>
}
}
font_sty = font_sty->next;
}
if( second != 100 ){ <.print font style css.> }
-_-_-
<..get font size..>
{ Q_CHAR *p;
second = (int)
( (int) get_long_int(match[3])
* (int) get_long_int(match[4])
/ base_font_size
);
while( second > 700 ){ second /= 10; }
p = match[3];
while( *p != ’\0’ ){
if( (*p < ’0’) || (*p > ’9’) ){ second = 100; break; }
p++;
}
<.inspect font-size argument.>
}
-_-_-
The following case handles cases like that of ‘Font("ecti","1095","10","100")’, where base_font_size is 11.
<..inspect font-size argument..>
if( (int) ( (double) get_long_int(match[2])
/ (int) get_long_int(match[4])
+ 0.5
)
== base_font_size
){
second = 100;
};
-_-_-
<..Font_css_base: .....>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Font_css_base: ", TRUE, lg_file);
status = scan_until_str("Font_css_mag: ", 1, status, lg_file);
status = scan_until_end_str("", 2, status, lg_file);
if( status ){
Font_css_base = match[1];
*(Font_css_base + (int) strlen((char *) Font_css_base) - 14) = ’\0’;
match[1] = (Q_CHAR *) malloc(70); max_match[1] = 70;
Font_css_mag = match[2];
match[2] = (Q_CHAR *) malloc(70); max_match[2] = 70;
} }
-_-_-
<..vars..>+
static char *Font_css_base = NULL,
*Font_css_mag = NULL;
static int base_font_size = 10;
-_-_-
<..print font style css..>
(IGNORED) fprintf(css_file,
(Font_css_base == NULL)? ".%s-%s" : Font_css_base,
match[1], match[2]);
if( !eq_str(match[4],"100") ){
(IGNORED) fprintf(css_file,
(Font_css_mag == NULL)? "x-x-%s" : Font_css_mag,
match[4]);
}
(IGNORED) fprintf(css_file, "{");
if( (second < 98) || (second > 102) ){
(IGNORED) fprintf(css_file, "font-size:%d%c;", second, ’%’);
}
if( font_sty ) {
(IGNORED) fprintf(css_file, "%s", font_sty->body);
}
(IGNORED) fprintf(css_file, "}\n");
-_-_-
<..print media style..>
(IGNORED) fprintf(css_file, "@media %s{", font_sty->media);
(IGNORED) fprintf(css_file,
(Font_css_base == NULL)? ".%s-%s" : Font_css_base,
match[1], match[2]);
if( !eq_str(match[4],"100") ){
(IGNORED) fprintf(css_file,
(Font_css_mag == NULL)? "x-x-%s" : Font_css_mag,
match[4]);
}
(IGNORED) fprintf(css_file, "{");
if( font_sty ) {
(IGNORED) fprintf(css_file, "%s", font_sty->body);
}
(IGNORED) fprintf(css_file, "}}\n");
-_-_-
‘Font_Css("4"): .small-caps{font-variant: small-caps; }’
<..process Font_Css(...):.....>
{ char *font_class [256];
int last_class;
<.find usage.>
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Font_Css(\"", TRUE, lg_file);
status = scan_until_str("\"): ", 1, status, lg_file);
status = scan_until_end_str("", 2, status, lg_file);
if( status ){ int i;
for(i=0; i<last_class; i++){
if( eq_str(match[1],font_class[i]) ){
(IGNORED) fprintf(css_file, "%s\n", match[2]);
break;
} } } } }
-_-_-
<..find usage..>
last_class = 0;
eoln_ch = (int) ’x’;
while( eoln_ch != EOF ) {
status = scan_str("Font_Class(", TRUE, lg_file);
status = scan_until_str(",\"", 1, status, lg_file);
status = scan_until_str("\"): ", 1, status, lg_file);
status = scan_until_end_str("", 2, status, lg_file);
if( status ){
font_class[last_class++] = match[1];
match[1] = (Q_CHAR *) malloc(7); max_match[1] = 7;
} }
<.rewind lg file.>
-_-_-