/[public]/psiconv/trunk/lib/psiconv/parse_layout.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_layout.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 65 Revision 142
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
22
21#include <stdlib.h> 23#include <stdlib.h>
22#include <math.h> 24#include <math.h>
23 25
24#include "data.h"
25#include "parse_routines.h" 26#include "parse_routines.h"
27#include "error.h"
28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
32
26 33
27int psiconv_parse_color(const psiconv_buffer buf, int lev, psiconv_u32 off, 34int psiconv_parse_color(const psiconv_buffer buf, int lev, psiconv_u32 off,
28 int *length, psiconv_color *result) 35 int *length, psiconv_color *result)
29{ 36{
30 int res = 0; 37 int res = 0;
145 else if (temp == 0x02) 152 else if (temp == 0x02)
146 (*result)->kind = psiconv_border_double; 153 (*result)->kind = psiconv_border_double;
147 else if (temp == 0x03) 154 else if (temp == 0x03)
148 (*result)->kind = psiconv_border_dotted; 155 (*result)->kind = psiconv_border_dotted;
149 else if (temp == 0x04) 156 else if (temp == 0x04)
150 (*result)->kind = psiconv_border_striped; 157 (*result)->kind = psiconv_border_dashed;
151 else if (temp == 0x05) 158 else if (temp == 0x05)
152 (*result)->kind = psiconv_border_dotstripe; 159 (*result)->kind = psiconv_border_dotdashed;
153 else if (temp == 0x06) 160 else if (temp == 0x06)
154 (*result)->kind = psiconv_border_dotdotstripe; 161 (*result)->kind = psiconv_border_dotdotdashed;
155 else { 162 else {
156 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')"); 163 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')");
157 (*result)->kind = psiconv_border_none; 164 (*result)->kind = psiconv_border_none;
158 } 165 }
159 psiconv_debug(lev+2,off+len,"Kind: %02x",temp); 166 psiconv_debug(lev+2,off+len,"Kind: %02x",temp);
161 168
162 psiconv_progress(lev+2,off+len,"Going to read border thickness"); 169 psiconv_progress(lev+2,off+len,"Going to read border thickness");
163 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng,&res); 170 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng,&res);
164 if (res) 171 if (res)
165 goto ERROR2; 172 goto ERROR2;
173#if 0
174 /* This seems no longer necessary to test? */
166 if (((*result)->kind != psiconv_border_solid) && 175 if (((*result)->kind != psiconv_border_solid) &&
167 ((*result)->kind != psiconv_border_double) && 176 ((*result)->kind != psiconv_border_double) &&
168 ((*result)->thickness != 0.0) && 177 ((*result)->thickness != 0.0) &&
169 (fabs((*result)->thickness - 1/20) >= 1/1000)) { 178 (fabs((*result)->thickness - 1/20) >= 1/1000)) {
170 psiconv_warn(lev+2,off, 179 psiconv_warn(lev+2,off,
171 "Border thickness specified for unlikely border type"); 180 "Border thickness specified for unlikely border type");
172 } 181 }
182#endif
173 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness); 183 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness);
174 len += leng; 184 len += leng;
175 185
176 psiconv_progress(lev+2,off+len,"Going to read the border color"); 186 psiconv_progress(lev+2,off+len,"Going to read the border color");
177 if ((psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color))) 187 if ((psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
178 goto ERROR2; 188 goto ERROR2;
179 len += leng; 189 len += leng;
180 190
181 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte " 191 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte "
182 "(0x01 expected)"); 192 "(0x00 or 0x01 expected)");
183 temp = psiconv_read_u8(buf,lev+2,off + len,&res); 193 temp = psiconv_read_u8(buf,lev+2,off + len,&res);
184 if (res) 194 if (res)
185 goto ERROR3; 195 goto ERROR3;
186 if (temp != 0x01) { 196 if ((temp != 0x01) && (temp != 0x00)) {
187 psiconv_warn(lev+2,off,"Unknown last byte in border specification"); 197 psiconv_warn(lev+2,off,"Unknown last byte in border specification");
188 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x", 198 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x or %02x",
189 temp,0x01); 199 temp,0x00,0x01);
190 } 200 }
191 len ++; 201 len ++;
192 202
193 if (length) 203 if (length)
194 *length = len; 204 *length = len;
444 "in paragraph layout codes list"); 454 "in paragraph layout codes list");
445 result->justify_ver = psiconv_justify_bottom; 455 result->justify_ver = psiconv_justify_bottom;
446 } 456 }
447 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 457 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
448 len ++; 458 len ++;
459 break;
449 case 0x07: 460 case 0x07:
450 psiconv_progress(lev+3,off+len,"Going to read interline distance"); 461 psiconv_progress(lev+3,off+len,"Going to read linespacing distance");
451 result->interline = psiconv_read_size(buf,lev+3,off+len,&leng,&res); 462 result->linespacing = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
452 if (res) 463 if (res)
453 goto ERROR1; 464 goto ERROR1;
454 len += leng; 465 len += leng;
455 break; 466 break;
456 case 0x08: 467 case 0x08:
457 psiconv_progress(lev+3,off+len,"Going to read interline exact"); 468 psiconv_progress(lev+3,off+len,"Going to read linespacing exact");
458 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng, 469 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
459 &result->interline_exact))) 470 &result->linespacing_exact)))
460 goto ERROR1; 471 goto ERROR1;
461 len += leng; 472 len += leng;
462 break; 473 break;
463 case 0x09: 474 case 0x09:
464 psiconv_progress(lev+3,off+len,"Going to read top space"); 475 psiconv_progress(lev+3,off+len,"Going to read top space");
465 result->top_space = psiconv_read_size(buf,lev+3,off+len,&leng,&res); 476 result->space_above = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
466 if (res) 477 if (res)
467 goto ERROR1; 478 goto ERROR1;
468 len += leng; 479 len += leng;
469 break; 480 break;
470 case 0x0a: 481 case 0x0a:
471 psiconv_progress(lev+3,off+len,"Going to read bottom space"); 482 psiconv_progress(lev+3,off+len,"Going to read bottom space");
472 result->bottom_space = psiconv_read_size(buf,lev+3,off+len,&leng,&res); 483 result->space_below = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
473 if (res) 484 if (res)
474 goto ERROR1; 485 goto ERROR1;
475 len += leng; 486 len += leng;
476 break; 487 break;
477 case 0x0b: 488 case 0x0b:
478 psiconv_progress(lev+3,off+len,"Going to read on one page"); 489 psiconv_progress(lev+3,off+len,"Going to read on one page");
479 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng, 490 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
480 &result->on_one_page))) 491 &result->keep_together)))
481 goto ERROR1; 492 goto ERROR1;
482 len += leng; 493 len += leng;
483 break; 494 break;
484 case 0x0c: 495 case 0x0c:
485 psiconv_progress(lev+3,off+len,"Going to read together with"); 496 psiconv_progress(lev+3,off+len,"Going to read together with");
486 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng, 497 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
487 &result->together_with))) 498 &result->keep_with_next)))
488 goto ERROR1; 499 goto ERROR1;
489 len += leng; 500 len += leng;
490 break; 501 break;
491 case 0x0d: 502 case 0x0d:
492 psiconv_progress(lev+3,off+len,"Going to read on next page"); 503 psiconv_progress(lev+3,off+len,"Going to read on next page");
497 break; 508 break;
498 case 0x0e: 509 case 0x0e:
499 psiconv_progress(lev+3,off+len,"Going to read no widow protection"); 510 psiconv_progress(lev+3,off+len,"Going to read no widow protection");
500 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng, 511 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
501 &result->no_widow_protection))) 512 &result->no_widow_protection)))
513 goto ERROR1;
514 len += leng;
515 break;
516 case 0x0f:
517 psiconv_progress(lev+3,off+len,"Going to read wrap to fit cell limits");
518 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
519 &result->wrap_to_fit_cell)))
502 goto ERROR1; 520 goto ERROR1;
503 len += leng; 521 len += leng;
504 break; 522 break;
505 case 0x10: 523 case 0x10:
506 psiconv_progress(lev+3,off+len,"Going to read border distance to text"); 524 psiconv_progress(lev+3,off+len,"Going to read border distance to text");
636 if (res) 654 if (res)
637 goto ERROR1; 655 goto ERROR1;
638 psiconv_debug(lev+3,off+len,"Id: %02x",id); 656 psiconv_debug(lev+3,off+len,"Id: %02x",id);
639 len ++; 657 len ++;
640 switch(id) { 658 switch(id) {
659 case 0x18:
660 psiconv_progress(lev+3,off+len,"Going to skip an unknown setting");
661 len ++;
662 break;
641 case 0x19: 663 case 0x19:
642 psiconv_progress(lev+3,off+len,"Going to read text color"); 664 psiconv_progress(lev+3,off+len,"Going to read text color");
643 if ((res = psiconv_parse_color(buf,lev+3,off+len, &leng,&temp_color))) 665 if ((res = psiconv_parse_color(buf,lev+3,off+len, &leng,&temp_color)))
644 goto ERROR1; 666 goto ERROR1;
645 psiconv_free_color(result->color); 667 psiconv_free_color(result->color);
651 if ((res = psiconv_parse_color(buf,lev+2,off+len, &leng,&temp_color))) 673 if ((res = psiconv_parse_color(buf,lev+2,off+len, &leng,&temp_color)))
652 goto ERROR1; 674 goto ERROR1;
653 psiconv_free_color(result->back_color); 675 psiconv_free_color(result->back_color);
654 result->back_color = temp_color; 676 result->back_color = temp_color;
655 len += leng; 677 len += leng;
678 break;
679 case 0x1b:
680 psiconv_progress(lev+3,off+len,"Going to skip an unknown setting");
681 len ++;
656 break; 682 break;
657 case 0x1c: 683 case 0x1c:
658 psiconv_progress(lev+3,off+len,"Going to read font size"); 684 psiconv_progress(lev+3,off+len,"Going to read font size");
659 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng,&res); 685 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
660 if (res) 686 if (res)
697 &result->underline))) 723 &result->underline)))
698 goto ERROR1; 724 goto ERROR1;
699 len += leng; 725 len += leng;
700 break; 726 break;
701 case 0x21: 727 case 0x21:
702 psiconv_progress(lev+3,off+len,"Going to read strike_out"); 728 psiconv_progress(lev+3,off+len,"Going to read strikethrough");
703 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng, 729 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
704 &result->strike_out))) 730 &result->strikethrough)))
705 goto ERROR1; 731 goto ERROR1;
706 len += leng; 732 len += leng;
707 break; 733 break;
708 case 0x22: 734 case 0x22:
709 psiconv_progress(lev+3,off+len,"Going to read font"); 735 psiconv_progress(lev+3,off+len,"Going to read font");
710 if ((res = psiconv_parse_font(buf,lev+3,off+len, &leng, &temp_font))) 736 if ((res = psiconv_parse_font(buf,lev+3,off+len, &leng, &temp_font)))
711 goto ERROR1; 737 goto ERROR1;
712 psiconv_free_font(result->font); 738 psiconv_free_font(result->font);
713 result->font = temp_font; 739 result->font = temp_font;
714 len += leng; 740 len += leng;
741 break;
742 case 0x23:
743 psiconv_progress(lev+3,off+len,"Going to skip an unknown setting");
744 len ++;
715 break; 745 break;
716 case 0x24: 746 case 0x24:
717 psiconv_progress(lev+3,off+len, 747 psiconv_progress(lev+3,off+len,
718 "Going to read unknown code 0x24 (%02x expected)", 0); 748 "Going to read unknown code 0x24 (%02x expected)", 0);
719 temp = psiconv_read_u8(buf,lev+3,off+len,&res); 749 temp = psiconv_read_u8(buf,lev+3,off+len,&res);

Legend:
Removed from v.65  
changed lines
  Added in v.142

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26