Skip to content

Commit

Permalink
migrate debug_* fields from OptionState to HandlePdf.config
Browse files Browse the repository at this point in the history
  • Loading branch information
gfngfn committed Oct 29, 2023
1 parent 1e236dc commit 3a2cadc
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 69 deletions.
56 changes: 34 additions & 22 deletions src/backend/handlePdf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ open HorzBox
type t =
| PDF of Pdf.t * Pdfpage.t Alist.t * abs_path

type config = {
debug_show_bbox : bool;
debug_show_space : bool;
debug_show_block_bbox : bool;
debug_show_block_space : bool;
debug_show_overfull : bool;
}

type 'o op_funcs = {
config : config;
graphics : (intermediate_horz_box list) GraphicD.t -> (point -> intermediate_horz_box list -> 'o list) -> 'o list;
text : horz_string_info -> point -> OutputText.t -> 'o list;
math : math_string_info -> point -> OutputText.t -> 'o list;
Expand Down Expand Up @@ -39,7 +47,8 @@ let pdfops_of_image imgkey pt wid hgt =
GraphicD.pdfops_of_image pt xratio yratio tag


let fs_pdf = {
let fs_pdf (config : config) = {
config = config;
graphics = GraphicD.to_pdfops;
text = pdfops_of_text;
math = pdfops_of_math;
Expand Down Expand Up @@ -67,7 +76,7 @@ let warn_ratios (fs : 'o op_funcs) (pbinfo : page_break_info) pt hgt dpt (ratios
match ratios with
| TooLong{ required = wid_required; actual = wid_actual } ->
Logging.warn_overfull_line pageno;
if OptionState.does_debug_show_overfull () then
if fs.config.debug_show_overfull then
List.append
(fs.test_frame color_show_overfull pt wid_actual hgt dpt)
(fs.test_frame color_show_overfull pt wid_required hgt dpt)
Expand All @@ -76,7 +85,7 @@ let warn_ratios (fs : 'o op_funcs) (pbinfo : page_break_info) pt hgt dpt (ratios

| TooShort{ required = wid_required; actual = wid_actual } ->
Logging.warn_underfull_line pageno;
if OptionState.does_debug_show_overfull () then
if fs.config.debug_show_overfull then
List.append
(fs.test_frame color_show_overfull pt wid_actual hgt dpt)
(fs.test_frame color_show_overfull pt wid_required hgt dpt)
Expand All @@ -91,7 +100,7 @@ let warn_reachability (fs : 'o op_funcs) (pbinfo : page_break_info) pt hgt dpt (
match reach with
| Unreachable ->
Logging.warn_unreachable pbinfo.current_page_number;
if OptionState.does_debug_show_overfull () then
if fs.config.debug_show_overfull then
let wid = Length.of_pdf_point 2. in (* temporary *)
fs.test_frame color_show_unreachable pt wid hgt dpt
else
Expand All @@ -112,7 +121,7 @@ let rec ops_of_evaled_horz_box (fs : 'o op_funcs) (pbinfo : page_break_info) ypo
match evhbmain with
| EvHorzEmpty ->
let opaccnew =
if OptionState.does_debug_show_space () then
if fs.config.debug_show_space then
let opsgr = fs.test_box color_show_space (xpos, yposbaseline) wid (Length.of_pdf_point 2.) in
Alist.append opacc opsgr
else
Expand Down Expand Up @@ -143,7 +152,7 @@ let rec ops_of_evaled_horz_box (fs : 'o op_funcs) (pbinfo : page_break_info) ypo
let opsmain =
fs.text hsinfo (xpos, yposbaseline +% hsinfo.rising) otxt
in
if OptionState.does_debug_show_bbox () then
if fs.config.debug_show_bbox then
let opsgr = fs.test_frame color_show_bbox (xpos, yposbaseline) wid hgt dpt in
List.append opsgr opsmain
else
Expand All @@ -157,7 +166,7 @@ let rec ops_of_evaled_horz_box (fs : 'o op_funcs) (pbinfo : page_break_info) ypo
let opsmain =
fs.math msinfo (xpos, yposbaseline) otxt
in
if OptionState.does_debug_show_bbox () then
if fs.config.debug_show_bbox then
let opsgr = fs.test_frame color_show_bbox (xpos, yposbaseline) wid hgt dpt in
List.append opsgr opsmain
else
Expand All @@ -172,7 +181,7 @@ let rec ops_of_evaled_horz_box (fs : 'o op_funcs) (pbinfo : page_break_info) ypo
in
let opaccnew =
(*
if OptionState.does_debug_show_bbox () then
if fs.config.debug_show_bbox then
Alist.append opaccsub (GraphicD.pdfops_test_frame (xpos, yposbaseline) wid hgt dpt)
else
*)
Expand All @@ -193,7 +202,7 @@ let rec ops_of_evaled_horz_box (fs : 'o op_funcs) (pbinfo : page_break_info) ypo
let opsgr = pdfops_of_graphics fs pbinfo gr in
let opaccsub = Alist.append opacc opsgr in
let opaccnew =
if OptionState.does_debug_show_bbox () then
if fs.config.debug_show_bbox then
let opsgr = fs.test_frame color_show_bbox (xpos, yposbaseline) wid hgt dpt in
Alist.append opaccsub opsgr
else
Expand Down Expand Up @@ -297,7 +306,7 @@ and ops_of_evaled_vert_box_list (fs : 'o op_funcs) pbinfo (xinit, yinit) opaccin
match evvb with
| EvVertFixedEmpty(debug_margins, vskip) ->
let opacc =
if OptionState.does_debug_show_block_space () then
if fs.config.debug_show_block_space then
let ops =
match debug_margins with
| Fixed -> fs.test_skip_fixed color_show_skip pos vskip
Expand All @@ -321,7 +330,7 @@ and ops_of_evaled_vert_box_list (fs : 'o op_funcs) pbinfo (xinit, yinit) opaccin
evhblst @|> (xpos, opacc) @|> List.fold_left (ops_of_evaled_horz_box fs pbinfo yposbaseline)
in
let opaccend =
if OptionState.does_debug_show_block_bbox () then
if fs.config.debug_show_block_bbox then
let wid = xposlast -% xpos in
Alist.append opaccend (fs.test_frame color_show_block_bbox (xpos, yposbaseline) wid hgt dpt)
else
Expand Down Expand Up @@ -376,25 +385,26 @@ let get_paper_height (paper : Pdfpaper.t) : length =


let opacc_of_body_and_footnote
(config : config)
(txtlen : length) (* -- for option `--debug-show-block-bbox` -- *)
(pbinfo : page_break_info)
((ptbody, evvblstbody) : (length * length) * evaled_vert_box list)
((ptfootnote, evvblstfootnote) : (length * length) * evaled_vert_box list)
: Pdfops.t Alist.t =

let fs = fs_pdf config in
let opaccbody =
let (_, opaccbody) = ops_of_evaled_vert_box_list fs_pdf pbinfo ptbody Alist.empty evvblstbody in
if OptionState.does_debug_show_block_bbox () then
Alist.append opaccbody (fs_pdf.test_scale color_show_frame ptbody txtlen)
let (_, opaccbody) = ops_of_evaled_vert_box_list fs pbinfo ptbody Alist.empty evvblstbody in
if config.debug_show_block_bbox then
Alist.append opaccbody (fs.test_scale color_show_frame ptbody txtlen)
else
opaccbody
in
let opaccfootnote =
let (_, opaccfootnote) = ops_of_evaled_vert_box_list fs_pdf pbinfo ptfootnote Alist.empty evvblstfootnote in
if OptionState.does_debug_show_block_bbox () then
let (_, opaccfootnote) = ops_of_evaled_vert_box_list fs pbinfo ptfootnote Alist.empty evvblstfootnote in
if fs.config.debug_show_block_bbox then
let wid = Length.of_pdf_point 5. in
let len = Length.of_pdf_point 1. in
Alist.append opaccfootnote (fs_pdf.test_box color_show_frame ptfootnote wid len)
Alist.append opaccfootnote (fs.test_box color_show_frame ptfootnote wid len)
else
opaccfootnote
in
Expand Down Expand Up @@ -425,6 +435,7 @@ let make_empty_page


let add_column_to_page
(config : config)
(Page(paper, pagecontsch, opacc, pbinfo))
(origin_shift : length)
(evvblstbody : evaled_vert_box list)
Expand All @@ -449,25 +460,26 @@ let add_column_to_page
content_origin
evvblstfootnote
in
opacc_of_body_and_footnote content_height pbinfo
opacc_of_body_and_footnote config content_height pbinfo
(posbody, evvblstbody)
(posfootnote, evvblstfootnote)
in
Page(paper, pagecontsch, Alist.cat opacc opacccolumn, pbinfo)


let write_page (Page(paper, _pagecontsch, opaccpage, pbinfo) : page) (pagepartsf : page_parts_scheme_func) ((PDF(pdf, pageacc, flnm)) : t) : t =
let write_page (config : config) (Page(paper, _pagecontsch, opaccpage, pbinfo) : page) (pagepartsf : page_parts_scheme_func) ((PDF(pdf, pageacc, flnm)) : t) : t =

let fs = fs_pdf config in
let paper_height = get_paper_height paper in

let pagepartssch = pagepartsf pbinfo in (* -- invokes the page-parts function -- *)
let (evvblst_header, _) = pagepartssch.header_content |> PageInfo.embed_page_info_vert pbinfo in
let pt_header = invert_coordinate paper_height pagepartssch.header_origin in
let (_, opacc_header) = ops_of_evaled_vert_box_list fs_pdf pbinfo pt_header opaccpage evvblst_header in
let (_, opacc_header) = ops_of_evaled_vert_box_list fs pbinfo pt_header opaccpage evvblst_header in

let (evvblst_footer, _) = pagepartssch.footer_content |> PageInfo.embed_page_info_vert pbinfo in
let pt_footer = invert_coordinate paper_height pagepartssch.footer_origin in
let (_, opacc_footer) = ops_of_evaled_vert_box_list fs_pdf pbinfo pt_footer opacc_header evvblst_footer in
let (_, opacc_footer) = ops_of_evaled_vert_box_list fs pbinfo pt_footer opacc_header evvblst_footer in

let oplst = Alist.to_list opacc_footer in

Expand Down
12 changes: 10 additions & 2 deletions src/backend/handlePdf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ type t

val create_empty_pdf : abs_path -> t

type config = {
debug_show_bbox : bool;
debug_show_space : bool;
debug_show_block_bbox : bool;
debug_show_block_space : bool;
debug_show_overfull : bool;
}

type page

val write_page : page -> page_parts_scheme_func -> t -> t
val write_page : config -> page -> page_parts_scheme_func -> t -> t

val write_to_file : t -> unit

val make_empty_page : paper_size:(length * length) -> page_break_info -> page_content_scheme -> page

val add_column_to_page : page -> length -> evaled_vert_box list -> evaled_vert_box list -> page
val add_column_to_page : config -> page -> length -> evaled_vert_box list -> evaled_vert_box list -> page
16 changes: 0 additions & 16 deletions src/backend/optionState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ open MyUtil
type build_state = {
input_file : abs_path;
output_file : abs_path option;
debug_show_bbox : bool;
debug_show_space : bool;
debug_show_block_bbox : bool;
debug_show_block_space : bool;
debug_show_overfull : bool;
type_check_only : bool;
}

Expand Down Expand Up @@ -42,12 +37,6 @@ let get () =
| Some(r) -> r


let get_build_state () =
match (get ()).command_state with
| BuildState(b) -> b
| _ -> assert false


let get_input_file () =
match (get ()).command_state with
| BuildState({ input_file; _ }) -> input_file
Expand All @@ -56,11 +45,6 @@ let get_input_file () =


let does_show_full_path () = (get ()).show_full_path
let does_debug_show_bbox () = (get_build_state ()).debug_show_bbox
let does_debug_show_space () = (get_build_state ()).debug_show_space
let does_debug_show_block_bbox () = (get_build_state ()).debug_show_block_bbox
let does_debug_show_block_space () = (get_build_state ()).debug_show_block_space
let does_debug_show_overfull () = (get_build_state ()).debug_show_overfull


let job_directory () =
Expand Down
10 changes: 0 additions & 10 deletions src/backend/optionState.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ open MyUtil
type build_state = {
input_file : abs_path;
output_file : abs_path option;
debug_show_bbox : bool;
debug_show_space : bool;
debug_show_block_bbox : bool;
debug_show_block_space : bool;
debug_show_overfull : bool;
type_check_only : bool;
}

Expand All @@ -33,10 +28,5 @@ val set : state -> unit
val get : unit -> state

val does_show_full_path : unit -> bool
val does_debug_show_bbox : unit -> bool
val does_debug_show_space : unit -> bool
val does_debug_show_block_bbox : unit -> bool
val does_debug_show_block_space : unit -> bool
val does_debug_show_overfull : unit -> bool

val job_directory : unit -> string
12 changes: 6 additions & 6 deletions src/backend/pageBreak.ml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ let chop_single_column_with_insertion (pbinfo : page_break_info) (content_height
chop_single_column pbinfo content_height (List.append pbvblst_inserted pbvblst)


let main (absname_out : abs_path) ~(paper_size : length * length) (columnhookf : column_hook_func) (pagecontf : page_content_scheme_func) (pagepartsf : page_parts_scheme_func) (vblst : vert_box list) : HandlePdf.t =
let main (pdf_config : HandlePdf.config) (absname_out : abs_path) ~(paper_size : length * length) (columnhookf : column_hook_func) (pagecontf : page_content_scheme_func) (pagepartsf : page_parts_scheme_func) (vblst : vert_box list) : HandlePdf.t =

let pdfinit = HandlePdf.create_empty_pdf absname_out in

Expand All @@ -704,8 +704,8 @@ let main (absname_out : abs_path) ~(paper_size : length * length) (columnhookf :
chop_single_column_with_insertion pbinfo pagecontsch.page_content_height columnhookf pbvblst
in
let page = HandlePdf.make_empty_page ~paper_size pbinfo pagecontsch in
let page = HandlePdf.add_column_to_page page Length.zero evvblstpage footnote in
let pdfaccnew = pdfacc |> HandlePdf.write_page page pagepartsf in
let page = HandlePdf.add_column_to_page pdf_config page Length.zero evvblstpage footnote in
let pdfaccnew = pdfacc |> HandlePdf.write_page pdf_config page pagepartsf in
match restopt with
| None -> pdfaccnew
| Some(rest) -> aux (pageno + 1) pdfaccnew rest
Expand All @@ -714,7 +714,7 @@ let main (absname_out : abs_path) ~(paper_size : length * length) (columnhookf :
aux 1 pdfinit pbvblst


let main_multicolumn ~(page_number_limit : int) (absname_out : abs_path) ~(paper_size : length * length) (origin_shifts : length list) (columnhookf : column_hook_func) (columnendhookf : column_hook_func) (pagecontf : page_content_scheme_func) (pagepartsf : page_parts_scheme_func) (vblst : vert_box list) : HandlePdf.t =
let main_multicolumn (pdf_config : HandlePdf.config) ~(page_number_limit : int) (absname_out : abs_path) ~(paper_size : length * length) (origin_shifts : length list) (columnhookf : column_hook_func) (columnendhookf : column_hook_func) (pagecontf : page_content_scheme_func) (pagepartsf : page_parts_scheme_func) (vblst : vert_box list) : HandlePdf.t =

let pdfinit = HandlePdf.create_empty_pdf absname_out in

Expand All @@ -734,7 +734,7 @@ let main_multicolumn ~(page_number_limit : int) (absname_out : abs_path) ~(paper
in

(* Adds the column to the page and invokes hook functions. *)
let page = HandlePdf.add_column_to_page page origin_shift body footnote in
let page = HandlePdf.add_column_to_page pdf_config page origin_shift body footnote in
begin
match restopt with
| None ->
Expand All @@ -761,7 +761,7 @@ let main_multicolumn ~(page_number_limit : int) (absname_out : abs_path) ~(paper
(* Creates an empty page and iteratively adds columns to it. *)
let page = HandlePdf.make_empty_page ~paper_size pbinfo pagecontsch in
let (page, rest) = iter_on_column pbinfo content_height page pbvbs origin_shifts in
let pdfacc = pdfacc |> HandlePdf.write_page page pagepartsf in
let pdfacc = pdfacc |> HandlePdf.write_page pdf_config page pagepartsf in
match rest with
| [] -> pdfacc
| _ :: _ -> iter_on_page (pageno + 1) pdfacc rest
Expand Down
4 changes: 2 additions & 2 deletions src/backend/pageBreak.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ exception PageNumberLimitExceeded of int

val solidify : vert_box list -> intermediate_vert_box list

val main : abs_path -> paper_size:(length * length) -> column_hook_func -> page_content_scheme_func -> page_parts_scheme_func -> vert_box list -> HandlePdf.t
val main : HandlePdf.config -> abs_path -> paper_size:(length * length) -> column_hook_func -> page_content_scheme_func -> page_parts_scheme_func -> vert_box list -> HandlePdf.t

val main_multicolumn : page_number_limit:int -> abs_path -> paper_size:(length * length) -> length list -> column_hook_func -> column_hook_func -> page_content_scheme_func -> page_parts_scheme_func -> vert_box list -> HandlePdf.t
val main_multicolumn : HandlePdf.config -> page_number_limit:int -> abs_path -> paper_size:(length * length) -> length list -> column_hook_func -> column_hook_func -> page_content_scheme_func -> page_parts_scheme_func -> vert_box list -> HandlePdf.t

val adjust_to_first_line : intermediate_vert_box list -> length * length

Expand Down
Loading

0 comments on commit 3a2cadc

Please sign in to comment.