Skip to content

Commit fe9f1c6

Browse files
committed
Add support for link targets (Issue #351)
1 parent e9f693b commit fe9f1c6

File tree

4 files changed

+59
-52
lines changed

4 files changed

+59
-52
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Refactored the PRE rendering code to work around compiler optimization bugs
44
(Issue #349)
5+
- Added support for links with targets (Issue #351)
56
- Fixed a table rowspan + valign bug (Issue #360)
67

78

doc/1-intro.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<head>
33
<meta name="author" content="Michael R Sweet">
44
<meta name="copyright" content="Copyright &copy; 1997-2019, All Rights Reserved.">
5-
<meta name="docversion" content="htmldoc-1.9.6">
5+
<meta name="docversion" content="htmldoc-1.9.7">
66
<meta name="keywords" content="Software">
77
<title>HTMLDOC Users Manual</title>
88
</head>

htmldoc/htmllib.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,6 +3643,9 @@ htmlFixLinks(tree_t *doc, // I - Top node
36433643
show_debug = 0;
36443644
else
36453645
show_debug = 1;
3646+
3647+
if (show_debug)
3648+
progress_error(HD_ERROR_NONE, "DEBUG: Updating links in document.");
36463649
}
36473650

36483651
while (tree)
@@ -3688,8 +3691,7 @@ htmlFixLinks(tree_t *doc, // I - Top node
36883691
}
36893692

36903693
if (show_debug)
3691-
progress_error(HD_ERROR_NONE, "DEBUG: Mapping \"%s\" to \"%s\"...\n",
3692-
href, full_href);
3694+
progress_error(HD_ERROR_NONE, "DEBUG: Mapping \"%s\" to \"%s\"...", href, full_href);
36933695

36943696
htmlSetVariable(tree, (uchar *)"_HD_FULL_HREF", (uchar *)full_href);
36953697
}

htmldoc/ps-pdf.cxx

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,10 +3388,28 @@ pdf_write_links(FILE *out) /* I - Output file */
33883388
* Link to external PDF file...
33893389
*/
33903390

3391+
const char *target = file_target((char *)r->data.link);
3392+
33913393
fputs("/S/GoToR", out);
3392-
fputs("/D[0/XYZ null null 0]", out);
3393-
fputs("/F", out);
3394-
write_string(out, r->data.link, 0);
3394+
if (target)
3395+
{
3396+
char url[1024], *urlptr;
3397+
3398+
fputs("/D", out);
3399+
write_string(out, (uchar *)target, 0);
3400+
3401+
strlcpy(url, (char *)r->data.link, sizeof(url));
3402+
if ((urlptr = strrchr(url, '#')) != NULL)
3403+
*urlptr = '\0';
3404+
3405+
fputs("/F", out);
3406+
write_string(out, (uchar *)url, 0);
3407+
}
3408+
else
3409+
{
3410+
fputs("/D[0/XYZ null null 0]/F", out);
3411+
write_string(out, r->data.link, 0);
3412+
}
33953413
}
33963414
else
33973415
{
@@ -3653,12 +3671,7 @@ render_contents(tree_t *t, /* I - Tree to parse */
36533671
* Add a page link...
36543672
*/
36553673

3656-
if (file_method((char *)link) == NULL &&
3657-
file_target((char *)link) != NULL)
3658-
link = (uchar *)file_target((char *)link) - 1; // Include # sign
3659-
3660-
new_render(*page, RENDER_LINK, x, *y, temp->width,
3661-
temp->height, link);
3674+
new_render(*page, RENDER_LINK, x, *y, temp->width, temp->height, link);
36623675

36633676
if (PSLevel == 0 && Links)
36643677
{
@@ -3674,6 +3687,15 @@ render_contents(tree_t *t, /* I - Tree to parse */
36743687
}
36753688
}
36763689

3690+
if ((link = htmlGetVariable(temp, (uchar *)"ID")) != NULL)
3691+
{
3692+
/*
3693+
* Add a target link...
3694+
*/
3695+
3696+
add_link(link, *page, (int)(*y + height));
3697+
}
3698+
36773699
switch (temp->markup)
36783700
{
36793701
case MARKUP_A :
@@ -4754,16 +4776,7 @@ parse_paragraph(tree_t *t, /* I - Tree to parse */
47544776
* Add a page link...
47554777
*/
47564778

4757-
if (file_method((char *)link) == NULL)
4758-
{
4759-
if (file_target((char *)link) != NULL)
4760-
link = (uchar *)file_target((char *)link) - 1; // Include # sign
4761-
else
4762-
link = (uchar *)file_basename((char *)link);
4763-
}
4764-
4765-
new_render(*page, RENDER_LINK, image_left + borderspace,
4766-
*y - temp->height, temp->width, temp->height, link);
4779+
new_render(*page, RENDER_LINK, image_left + borderspace, *y - temp->height, temp->width, temp->height, link);
47674780
}
47684781

47694782
*y -= borderspace;
@@ -4846,16 +4859,7 @@ parse_paragraph(tree_t *t, /* I - Tree to parse */
48464859
* Add a page link...
48474860
*/
48484861

4849-
if (file_method((char *)link) == NULL)
4850-
{
4851-
if (file_target((char *)link) != NULL)
4852-
link = (uchar *)file_target((char *)link) - 1; // Include # sign
4853-
else
4854-
link = (uchar *)file_basename((char *)link);
4855-
}
4856-
4857-
new_render(*page, RENDER_LINK, image_right + borderspace,
4858-
*y - temp->height, temp->width, temp->height, link);
4862+
new_render(*page, RENDER_LINK, image_right + borderspace, *y - temp->height, temp->width, temp->height, link);
48594863
}
48604864

48614865
*y -= borderspace;
@@ -5163,6 +5167,15 @@ parse_paragraph(tree_t *t, /* I - Tree to parse */
51635167
linetype = NULL;
51645168
}
51655169

5170+
if ((link = htmlGetVariable(temp, (uchar *)"ID")) != NULL)
5171+
{
5172+
/*
5173+
* Add a target link...
5174+
*/
5175+
5176+
add_link(link, *page, (int)(*y + height));
5177+
}
5178+
51665179
switch (temp->markup)
51675180
{
51685181
case MARKUP_A :
@@ -5289,16 +5302,7 @@ parse_paragraph(tree_t *t, /* I - Tree to parse */
52895302
* Add a page link...
52905303
*/
52915304

5292-
if (file_method((char *)link) == NULL)
5293-
{
5294-
if (file_target((char *)link) != NULL)
5295-
link = (uchar *)file_target((char *)link) - 1; // Include # sign
5296-
else
5297-
link = (uchar *)file_basename((char *)link);
5298-
}
5299-
5300-
new_render(*page, RENDER_LINK, linex, *y + offset, temp->width,
5301-
temp->height, link);
5305+
new_render(*page, RENDER_LINK, linex, *y + offset, temp->width, temp->height, link);
53025306
}
53035307

53045308
linex += temp_width;
@@ -5471,16 +5475,7 @@ parse_pre(tree_t *t, /* I - Tree to parse */
54715475
* Add a page link...
54725476
*/
54735477

5474-
if (file_method((char *)link) == NULL)
5475-
{
5476-
if (file_target((char *)link) != NULL)
5477-
link = (uchar *)file_target((char *)link) - 1; // Include # sign
5478-
else
5479-
link = (uchar *)file_basename((char *)link);
5480-
}
5481-
5482-
new_render(*page, RENDER_LINK, *x, *y, start->width,
5483-
start->height, link);
5478+
new_render(*page, RENDER_LINK, *x, *y, start->width, start->height, link);
54845479

54855480
if (PSLevel == 0 && Links)
54865481
{
@@ -5496,6 +5491,15 @@ parse_pre(tree_t *t, /* I - Tree to parse */
54965491
}
54975492
}
54985493

5494+
if ((link = htmlGetVariable(start, (uchar *)"ID")) != NULL)
5495+
{
5496+
/*
5497+
* Add a target link...
5498+
*/
5499+
5500+
add_link(link, *page, (int)(*y + height));
5501+
}
5502+
54995503
switch (start->markup)
55005504
{
55015505
case MARKUP_A :

0 commit comments

Comments
 (0)