Skip to content

Commit

Permalink
Add --pre-indent option and corresponding GUI support (Issue #505)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Sep 13, 2023
1 parent 3cdeb68 commit af6e9eb
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changes in HTMLDOC v1.9.17

- Added new `--pre-indent` option to control indentation of pre-formatted text
(Issue #505)
- Now link to CUPS library instead of embedding its HTTP code.
- Fixed multiple conversions of UTF-8 HTML files from the GUI (Issue #496)
- Fixed a compile bug on Solaris (Issue #498)
Expand Down
4 changes: 4 additions & 0 deletions doc/3-cmdref.html
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ <H3>--portrait</H3>

<P>This option is only available when generating PostScript or PDF files.

<H3>--pdf-indent margin</H3>

<p>The <CODE>--pdf-indent</CODE> option specifies the indentation for pre-formatted content. The default units are points (1 point = 1/72nd inch); the suffixes "in", "cm", and "mm" specify inches, centimeters, and millimeters, respectively.

<H3>--pscommands</H3>

<p>The <CODE>--pscommands</CODE> option specifies that PostScript device commands should be written to the output files.
Expand Down
9 changes: 6 additions & 3 deletions doc/htmldoc.man
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\"
.\" Manual page for HTMLDOC, a HTML document processing program.
.\"
.\" Copyright 2011-2022 by Michael R Sweet.
.\" Copyright 2011-2023 by Michael R Sweet.
.\" Copyright 1997-2010 by msweet.org.
.\"
.\" This program is free software. Distribution and use rights are outlined
.\" in the file "COPYING".
.\"
.TH htmldoc 1 "HTMLDOC 1.9.16" "2022-02-07" "Michael R Sweet"
.TH htmldoc 1 "HTMLDOC 1.9.17" "2023-09-13" "Michael R Sweet"
.SH NAME
htmldoc \- convert html source files into html, postscript, or pdf.
.SH SYNOPSIS
Expand Down Expand Up @@ -266,6 +266,9 @@ Specifies a search path for files in a document.
.BI \-\-permissions " permission[,permission,...]"
Specifies document permissions for encrypted PDF files. The following permissions are understood: all, none, annotate, no-annotate, copy, no-copy, modify, no-modify, print, and no-print. Separate multiple permissions with commas.
.TP 5
.BI \-\-pre\-indent " distance"
Specifies the indentation of pre-formatted text in points (no suffix or ##pt), inches (##in), centimeters (##cm), or millimeters (##mm).
.TP 5
.B \-\-pscommands
Specifies that PostScript setpagedevice commands should be included in the output.
.TP 5
Expand Down Expand Up @@ -429,7 +432,7 @@ https://www.msweet.org/htmldoc
.SH AUTHOR
Michael R Sweet
.SH LEGAL STUFF
HTMLDOC is copyright \[co] 1997-2022 by Michael R Sweet.
HTMLDOC is copyright \[co] 1997-2023 by Michael R Sweet.
.PP
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License version 2 as published by the Free
Expand Down
22 changes: 18 additions & 4 deletions htmldoc/gui.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// GUI routines for HTMLDOC, an HTML document processing program.
//
// Copyright © 2011-2022 by Michael R Sweet.
// Copyright © 2011-2023 by Michael R Sweet.
// Copyright © 1997-2010 by Easy Software Products. All rights reserved.
//
// This program is free software. Distribution and use rights are outlined in
Expand Down Expand Up @@ -726,10 +726,15 @@ GUI::GUI(const char *filename) // Book file to load initially
charset->callback((Fl_Callback *)changeCB, this);
charset->tooltip("Choose the encoding of text.");

group = new Fl_Group(200, 255, 285, 25, "Options: ");
preIndent = new Fl_Input(200, 255, 60, 25, "PRE Indent: ");
preIndent->when(FL_WHEN_CHANGED);
preIndent->callback((Fl_Callback *)changeCB, this);
preIndent->tooltip("Enter the indentation for pre-formatted text.");

group = new Fl_Group(200, 285, 285, 25, "Options: ");
group->align(FL_ALIGN_LEFT);

embedFonts = new Fl_Check_Button(200, 255, 110, 25, "Embed Fonts");
embedFonts = new Fl_Check_Button(200, 285, 110, 25, "Embed Fonts");
embedFonts->callback((Fl_Callback *)changeCB, this);
embedFonts->tooltip("Check to embed fonts in the output file.");

Expand Down Expand Up @@ -1292,6 +1297,7 @@ GUI::loadSettings()
PDFEffectDuration = effectDuration->value();
Links = links->value();
EmbedFonts = embedFonts->value();
PreIndent = get_measurement((char *)preIndent->value());

Encryption = encryptionYes->value();
Permissions = -64;
Expand Down Expand Up @@ -1497,6 +1503,9 @@ GUI::newBook(void)
break;
}

snprintf(size, sizeof(size), "%.2fin", PreIndent / 72.0f);
preIndent->value(size);

compression->value(Compression);
compGroup->deactivate();

Expand Down Expand Up @@ -2193,6 +2202,8 @@ GUI::parseOptions(const char *line) // I - Line from file
break;
}
}
else if (strcmp(temp, "--pre-indent") == 0)
preIndent->value(temp2);
else if (strcmp(temp, "--pagemode") == 0)
{
for (i = 0; i < (int)(sizeof(PDFModes) / sizeof(PDFModes[0])); i ++)
Expand Down Expand Up @@ -2535,6 +2546,9 @@ GUI::saveBook(const char *filename) // I - Name of book file
fprintf(fp, " --headfootfont %s", fonts[headFootFont->value()]);
fprintf(fp, " --charset %s", charset->text(charset->value()));

if (pageLeft->size() > 0)
fprintf(fp, " --pre-indent %s", preIndent->value());

if (typePDF->value())
{
if (links->value())
Expand Down Expand Up @@ -4270,7 +4284,7 @@ GUI::showAboutCB(void)
label->image(&logo);

label = new Fl_Box(60, 45, 530, 35,
"HTMLDOC " SVERSION "\nCopyright © 2011-2022 by Michael R Sweet."
"HTMLDOC " SVERSION "\nCopyright © 2011-2023 by Michael R Sweet."
);
label->align(FL_ALIGN_TOP_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);

Expand Down
3 changes: 2 additions & 1 deletion htmldoc/gui.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GUI definitions for HTMLDOC, an HTML document processing program.
*
* Copyright 2011-2020 by Michael R Sweet.
* Copyright 2011-2023 by Michael R Sweet.
* Copyright 1997-2010 by Easy Software Products. All rights reserved.
*
* This program is free software. Distribution and use rights are outlined in
Expand Down Expand Up @@ -134,6 +134,7 @@ class GUI
Fl_Counter *fontBaseSize,
*fontSpacing,
*headFootSize;
Fl_Input *preIndent;
Fl_Choice *charset;
Fl_Check_Button *embedFonts;

Expand Down
2 changes: 1 addition & 1 deletion htmldoc/html.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ write_header(FILE **out, /* IO - Output file */
fprintf(*out, "H6 { font-family: %s; }\n", families[_htmlHeadingFont]);
fputs("SUB { font-size: smaller; }\n", *out);
fputs("SUP { font-size: smaller; }\n", *out);
fputs("PRE { font-family: monospace; margin-left: 36pt; }\n", *out);
fprintf(*out, "PRE { font-family: monospace; margin-left: %dpt; }\n", PreIndent);

if (!LinkStyle)
fputs("A { text-decoration: none; }\n", *out);
Expand Down
10 changes: 10 additions & 0 deletions htmldoc/htmldoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,14 @@ main(int argc, /* I - Number of command-line arguments */
}
else if (compare_strings(argv[i], "--portrait", 4) == 0)
Landscape = 0;
else if (compare_strings(argv[i], "--pre-indent", 5) == 0)
{
i ++;
if (i < argc)
PreIndent = get_measurement(argv[i]);
else
usage(argv[i - 1]);
}
else if (compare_strings(argv[i], "--proxy", 4) == 0)
{
i ++;
Expand Down Expand Up @@ -2171,6 +2179,8 @@ parse_options(const char *line, // I - Options from book file
PageTop = get_measurement(temp2);
else if (strcmp(temp, "--bottom") == 0)
PageBottom = get_measurement(temp2);
else if (strcmp(temp, "--pre-indent") == 0)
PreIndent = get_measurement(temp2);
else if (strcmp(temp, "--header") == 0)
get_format(temp2, Header);
else if (strcmp(temp, "--header1") == 0)
Expand Down
4 changes: 3 additions & 1 deletion htmldoc/htmldoc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Header file for HTMLDOC, a HTML document processing program.
*
* Copyright 2011-2020 by Michael R Sweet.
* Copyright 2011-2023 by Michael R Sweet.
* Copyright 1997-2010 by Easy Software Products. All rights reserved.
*
* This program is free software. Distribution and use rights are outlined in
Expand Down Expand Up @@ -170,6 +170,8 @@ VAR int PageWidth VALUE(595), /* Page width in points */
Landscape VALUE(0), /* Landscape orientation? */
NumberUp VALUE(1); /* Number-up pages */

VAR int PreIndent VALUE(36); /* Indentation of PRE content */

VAR typeface_t HeadFootType VALUE(TYPE_HELVETICA);
/* Typeface for header & footer */
VAR style_t HeadFootStyle VALUE(STYLE_NORMAL);
Expand Down
2 changes: 1 addition & 1 deletion htmldoc/htmlsep.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ write_header(FILE **out, /* IO - Output file */
fprintf(*out, "H6 { font-family: %s; }\n", families[_htmlHeadingFont]);
fputs("SUB { font-size: smaller; }\n", *out);
fputs("SUP { font-size: smaller; }\n", *out);
fputs("PRE { font-family: monospace; margin-left: 36pt; }\n", *out);
fprintf(*out, "PRE { font-family: monospace; margin-left: %dpt; }\n", PreIndent);

if (!LinkStyle)
fputs("A { text-decoration: none; }\n", *out);
Expand Down
4 changes: 2 additions & 2 deletions htmldoc/ps-pdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4391,12 +4391,12 @@ parse_doc(tree_t *t, /* I - Tree to parse */
*needspace = 1;
}

*left += 36.0f;
*left += (float)PreIndent;
*x = *left;

parse_pre(t, *left, *right, *bottom, *top, x, y, page, *needspace);

*left -= 36.0f;
*left -= (float)PreIndent;
*x = *left;
*needspace = 1;
break;
Expand Down

0 comments on commit af6e9eb

Please sign in to comment.