From e3ef897e17cf74a686ec213e362a869d4a9b77f0 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sat, 14 May 2011 16:28:23 +0000 Subject: Give -Thtml and -Txhtml the gift of recognising escapes when calculating widths (e.g., `Bl -tag -width "\s[blahblah]bar"). This has long since been done for -Tascii but escaped noticed with -T[x]html. --- html.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index b1ba0dd2..8fb81c51 100644 --- a/html.c +++ b/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.137 2011/04/30 22:24:31 kristaps Exp $ */ +/* $Id: html.c,v 1.138 2011/05/14 16:28:23 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -31,6 +31,7 @@ #include #include "mandoc.h" +#include "libmandoc.h" #include "out.h" #include "html.h" #include "main.h" @@ -294,6 +295,41 @@ print_metaf(struct html *h, enum mandoc_esc deco) print_otag(h, TAG_I, 0, NULL); } +int +html_strlen(const char *cp) +{ + int ssz, sz; + const char *seq, *p; + + /* + * Account for escaped sequences within string length + * calculations. This follows the logic in term_strlen() as we + * must calculate the width of produced strings. + * Assume that characters are always width of "1". This is + * hacky, but it gets the job done for approximation of widths. + */ + + sz = 0; + while (NULL != (p = strchr(cp, '\\'))) { + sz += (int)(p - cp); + ++cp; + switch (mandoc_escape(&cp, &seq, &ssz)) { + case (ESCAPE_ERROR): + return(sz); + case (ESCAPE_PREDEF): + sz++; + break; + case (ESCAPE_SPECIAL): + sz++; + break; + default: + break; + } + } + + assert(sz >= 0); + return(sz + strlen(cp)); +} static int print_encode(struct html *h, const char *p, int norecurse) -- cgit v1.2.3