@@ -2490,12 +2490,79 @@ scan_special_trailerid (unsigned char *id1, unsigned char *id2,
24902490 return error ;
24912491}
24922492
2493+ static void
2494+ scan_special_config (const char * * start , const char * end , int * opt_flags ,
2495+ int * compression_level ,
2496+ double * annot_grow_x , double * annot_grow_y )
2497+ {
2498+ /* This section of code mirrors read_config_special() in `dvipdfm-x/dvipdfmx.c`. */
2499+
2500+ skip_white (start , end );
2501+ if (* start >= end )
2502+ return ;
2503+
2504+ char * option = parse_ident (start , end );
2505+ if (!option )
2506+ return ;
2507+
2508+ char * arg = NULL ;
2509+ skip_white (start , end );
2510+ if (* start < end ) {
2511+ if (* * start == '"' )
2512+ arg = parse_c_string (start , end );
2513+ else
2514+ arg = parse_ident (start , end );
2515+ }
2516+
2517+ /* This section of code implements a subset of do_args_second_pass() in the same file. */
2518+
2519+ if (streq_ptr (option , "C" ) && arg && opt_flags ) {
2520+ char * num_end ;
2521+ int flags = (unsigned ) strtol (arg , & num_end , 0 );
2522+ if (num_end == arg )
2523+ dpx_warning ("Invalid dvipdfmx compatibility flag: '%s'" , arg );
2524+ else if (flags < 0 )
2525+ * opt_flags = - flags ;
2526+ else
2527+ * opt_flags |= flags ;
2528+ } else if (streq_ptr (option , "z" ) && arg && compression_level ) {
2529+ * compression_level = atoi (arg );
2530+ } else if (streq_ptr (option , "g" ) && arg && annot_grow_x && annot_grow_y ) {
2531+ const char * comma = strchr (arg , ',' );
2532+ const char * arg_ptr = arg ; /* dpx_until_read_length changes the pointer */
2533+ const char * arg_end = arg + strlen (arg );
2534+ int error ;
2535+ if (comma ) {
2536+ error = dpx_util_read_length (annot_grow_x , 1.0 , & arg_ptr , comma );
2537+ arg_ptr = comma + 1 ;
2538+ if (!error )
2539+ error = dpx_util_read_length (annot_grow_y , 1.0 , & arg_ptr , arg_end );
2540+ } else {
2541+ error = dpx_util_read_length (annot_grow_x , 1.0 , & arg_ptr , arg_end );
2542+ if (!error )
2543+ * annot_grow_y = * annot_grow_x ;
2544+ }
2545+ if (error ) {
2546+ dpx_warning ("Error reading argument for \"-g\" option: %s" , arg );
2547+ }
2548+ } else {
2549+ dpx_warning ("Tectonic doesn't support '%s' config special"
2550+ " or the argument is missing" , option );
2551+ }
2552+
2553+ free (arg );
2554+ free (option );
2555+ }
2556+
24932557static int
24942558scan_special (double * wd , double * ht , double * xo , double * yo , int * lm ,
24952559 int * majorversion , int * minorversion ,
2560+ int * compression_level ,
2561+ double * annot_grow_x , double * annot_grow_y ,
24962562 int * enable_encryption , int * key_bits , int32_t * permission ,
24972563 char * opassword , char * upassword ,
24982564 int * has_id , unsigned char * id1 , unsigned char * id2 ,
2565+ int * opt_flags ,
24992566 const char * buf , uint32_t size )
25002567{
25012568 char * q ;
@@ -2626,7 +2693,7 @@ scan_special (double *wd, double *ht, double *xo, double *yo, int *lm,
26262693 * enable_encryption = 1 ;
26272694 error = scan_special_encrypt (key_bits , permission , opassword , upassword , & p , endptr );
26282695 } else if (ns_dvipdfmx && streq_ptr (q , "config" )) {
2629- dpx_warning ( "Tectonic does not support `config' special. Ignored." );
2696+ scan_special_config ( & p , endptr , opt_flags , compression_level , annot_grow_x , annot_grow_y );
26302697 } else if (has_id && id1 && id2 && ns_pdf && !strcmp (q , "trailerid" )) {
26312698 error = scan_special_trailerid (id1 , id2 , & p , endptr );
26322699 if (error ) {
@@ -2648,9 +2715,12 @@ dvi_scan_specials (int page_no,
26482715 double * page_width , double * page_height ,
26492716 double * x_offset , double * y_offset , int * landscape ,
26502717 int * majorversion , int * minorversion ,
2718+ int * compression_level ,
2719+ double * annot_grow_x , double * annot_grow_y ,
26512720 int * do_enc , int * key_bits , int32_t * permission ,
26522721 char * owner_pw , char * user_pw ,
2653- int * has_id , unsigned char * id1 , unsigned char * id2 )
2722+ int * has_id , unsigned char * id1 , unsigned char * id2 ,
2723+ int * opt_flags )
26542724{
26552725 uint32_t offset ;
26562726 unsigned char opcode ;
@@ -2694,8 +2764,11 @@ dvi_scan_specials (int page_no,
26942764 _tt_abort ("Reading DVI file failed!" );
26952765 if (scan_special (page_width , page_height , x_offset , y_offset , landscape ,
26962766 majorversion , minorversion ,
2767+ compression_level ,
2768+ annot_grow_x , annot_grow_y ,
26972769 do_enc , key_bits , permission , owner_pw , user_pw ,
26982770 has_id , id1 , id2 ,
2771+ opt_flags ,
26992772 buf , size ))
27002773 dpx_warning ("Reading special command failed: \"%.*s\"" , size , buf );
27012774#undef buf
0 commit comments