diff options
author | Vincent Sanders <vince@kyllikki.org> | 2020-05-19 23:38:34 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2020-05-19 23:38:34 +0100 |
commit | 6fe2f7de473246177eb21ee5cff7cfe2ae4bbe48 (patch) | |
tree | 7421d0d4f677115a2ea9aa6207282f99543e9d83 /content/handlers | |
parent | 605234c3d23279419df72b0e553509ca95490769 (diff) | |
download | netsurf-6fe2f7de473246177eb21ee5cff7cfe2ae4bbe48.tar.gz netsurf-6fe2f7de473246177eb21ee5cff7cfe2ae4bbe48.tar.bz2 |
do not export texplain interfaces unnecessarily
Diffstat (limited to 'content/handlers')
-rw-r--r-- | content/handlers/text/textplain.c | 308 | ||||
-rw-r--r-- | content/handlers/text/textplain.h | 54 |
2 files changed, 173 insertions, 189 deletions
diff --git a/content/handlers/text/textplain.c b/content/handlers/text/textplain.c index a233d827f..501ba1d34 100644 --- a/content/handlers/text/textplain.c +++ b/content/handlers/text/textplain.c @@ -594,6 +594,94 @@ static content_type textplain_content_type(void) /** + * Return byte offset within UTF8 textplain content. + * + * given the co-ordinates of a point within a textplain content. 'dir' + * specifies the direction in which to search (-1 = above-left, +1 = + * below-right) if the co-ordinates are not contained within a line. + * + * \param[in] c content of type CONTENT_TEXTPLAIN + * \param[in] x x ordinate of point + * \param[in] y y ordinate of point + * \param[in] dir direction of search if not within line + * \return byte offset of character containing (or nearest to) point + */ +static size_t +textplain_offset_from_coords(struct content *c, int x, int y, int dir) +{ + textplain_content *textc = (textplain_content *) c; + float line_height = textplain_line_height(); + struct textplain_line *line; + const char *text; + unsigned nlines; + size_t length; + int idx; + + assert(c != NULL); + + y = (int)((float)(y - MARGIN) / line_height); + x -= MARGIN; + + nlines = textc->physical_line_count; + if (!nlines) + return 0; + + if (y <= 0) y = 0; + else if ((unsigned)y >= nlines) + y = nlines - 1; + + line = &textc->physical_line[y]; + text = textc->utf8_data + line->start; + length = line->length; + idx = 0; + + while (x > 0) { + size_t next_offset = 0; + int width = INT_MAX; + + while (next_offset < length && text[next_offset] != '\t') { + next_offset = utf8_next(text, length, next_offset); + } + + if (next_offset < length) { + guit->layout->width(&textplain_style, + text, + next_offset, + &width); + } + + if (x <= width) { + int pixel_offset; + size_t char_offset; + + guit->layout->position(&textplain_style, + text, next_offset, x, + &char_offset, &pixel_offset); + + idx += char_offset; + break; + } + + x -= width; + length -= next_offset; + text += next_offset; + idx += next_offset; + + /* check if it's within the tab */ + width = textplain_tab_width - (width % textplain_tab_width); + if (x <= width) break; + + x -= width; + length--; + text++; + idx++; + } + + return line->start + idx; +} + + +/** * Handle mouse clicks and movements in a TEXTPLAIN content window. * * \param c content of type textplain @@ -1212,6 +1300,91 @@ textplain_coord_from_offset(const char *text, size_t offset, size_t length) return x; } + +/** + * Retrieve number of lines in content + * + * \param[in] c Content to retrieve line count from + * \return Number of lines + */ +static unsigned long textplain_line_count(struct content *c) +{ + textplain_content *text = (textplain_content *) c; + + assert(c != NULL); + + return text->physical_line_count; +} + + +/** + * Return a pointer to the requested line of text. + * + * \param[in] c content of type CONTENT_TEXTPLAIN + * \param[in] lineno line number + * \param[out] poffset receives byte offset of line start within text + * \param[out] plen receives length of returned line + * \return pointer to text, or NULL if invalid line number + */ +static char * +textplain_get_line(struct content *c, + unsigned lineno, + size_t *poffset, + size_t *plen) +{ + textplain_content *text = (textplain_content *) c; + struct textplain_line *line; + + assert(c != NULL); + + if (lineno >= text->physical_line_count) + return NULL; + line = &text->physical_line[lineno]; + + *poffset = line->start; + *plen = line->length; + return text->utf8_data + line->start; +} + + +/** + * Find line number of byte in text + * + * Given a byte offset within the text, return the line number + * of the line containing that offset. + * + * \param[in] c content of type CONTENT_TEXTPLAIN + * \param[in] offset byte offset within textual representation + * \return line number, or -1 if offset invalid (larger than size) + */ +static int textplain_find_line(struct content *c, unsigned offset) +{ + textplain_content *text = (textplain_content *) c; + struct textplain_line *line; + int nlines; + int lineno = 0; + + assert(c != NULL); + + line = text->physical_line; + nlines = text->physical_line_count; + + if (offset > text->utf8_data_size) { + return -1; + } + +/* \todo - implement binary search here */ + while (lineno < nlines && line[lineno].start < offset) { + lineno++; + } + if (line[lineno].start > offset) { + lineno--; + } + + return lineno; +} + + /** * Finds all occurrences of a given string in a textplain content * @@ -1369,15 +1542,6 @@ nserror textplain_init(void) } -/* exported interface documented in html/textplain.h */ -unsigned long textplain_line_count(struct content *c) -{ - textplain_content *text = (textplain_content *) c; - - assert(c != NULL); - - return text->physical_line_count; -} /* exported interface documented in html/textplain.h */ @@ -1392,81 +1556,6 @@ size_t textplain_size(struct content *c) /* exported interface documented in html/textplain.h */ -size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir) -{ - textplain_content *textc = (textplain_content *) c; - float line_height = textplain_line_height(); - struct textplain_line *line; - const char *text; - unsigned nlines; - size_t length; - int idx; - - assert(c != NULL); - - y = (int)((float)(y - MARGIN) / line_height); - x -= MARGIN; - - nlines = textc->physical_line_count; - if (!nlines) - return 0; - - if (y <= 0) y = 0; - else if ((unsigned)y >= nlines) - y = nlines - 1; - - line = &textc->physical_line[y]; - text = textc->utf8_data + line->start; - length = line->length; - idx = 0; - - while (x > 0) { - size_t next_offset = 0; - int width = INT_MAX; - - while (next_offset < length && text[next_offset] != '\t') { - next_offset = utf8_next(text, length, next_offset); - } - - if (next_offset < length) { - guit->layout->width(&textplain_style, - text, - next_offset, - &width); - } - - if (x <= width) { - int pixel_offset; - size_t char_offset; - - guit->layout->position(&textplain_style, - text, next_offset, x, - &char_offset, &pixel_offset); - - idx += char_offset; - break; - } - - x -= width; - length -= next_offset; - text += next_offset; - idx += next_offset; - - /* check if it's within the tab */ - width = textplain_tab_width - (width % textplain_tab_width); - if (x <= width) break; - - x -= width; - length--; - text++; - idx++; - } - - return line->start + idx; -} - - -/* exported interface documented in html/textplain.h */ void textplain_coords_from_range(struct content *c, unsigned start, @@ -1522,57 +1611,6 @@ textplain_coords_from_range(struct content *c, /* exported interface documented in html/textplain.h */ char * -textplain_get_line(struct content *c, - unsigned lineno, - size_t *poffset, - size_t *plen) -{ - textplain_content *text = (textplain_content *) c; - struct textplain_line *line; - - assert(c != NULL); - - if (lineno >= text->physical_line_count) - return NULL; - line = &text->physical_line[lineno]; - - *poffset = line->start; - *plen = line->length; - return text->utf8_data + line->start; -} - - -/* exported interface documented in html/textplain.h */ -int textplain_find_line(struct content *c, unsigned offset) -{ - textplain_content *text = (textplain_content *) c; - struct textplain_line *line; - int nlines; - int lineno = 0; - - assert(c != NULL); - - line = text->physical_line; - nlines = text->physical_line_count; - - if (offset > text->utf8_data_size) { - return -1; - } - -/* \todo - implement binary search here */ - while (lineno < nlines && line[lineno].start < offset) { - lineno++; - } - if (line[lineno].start > offset) { - lineno--; - } - - return lineno; -} - - -/* exported interface documented in html/textplain.h */ -char * textplain_get_raw_data(struct content *c, unsigned start, unsigned end, diff --git a/content/handlers/text/textplain.h b/content/handlers/text/textplain.h index 9c6ad9222..a2cfb5e00 100644 --- a/content/handlers/text/textplain.h +++ b/content/handlers/text/textplain.h @@ -26,11 +26,7 @@ #ifndef NETSURF_HTML_TEXTPLAIN_H #define NETSURF_HTML_TEXTPLAIN_H -#include <stddef.h> -#include "netsurf/mouse.h" - struct content; -struct hlcache_handle; struct rect; /** @@ -42,15 +38,6 @@ nserror textplain_init(void); /** - * Retrieve number of lines in content - * - * \param[in] c Content to retrieve line count from - * \return Number of lines - */ -unsigned long textplain_line_count(struct content *c); - - -/** * Retrieve the size (in bytes) of text data * * \param[in] c Content to retrieve size of @@ -60,22 +47,6 @@ size_t textplain_size(struct content *c); /** - * Return byte offset within UTF8 textplain content. - * - * given the co-ordinates of a point within a textplain content. 'dir' - * specifies the direction in which to search (-1 = above-left, +1 = - * below-right) if the co-ordinates are not contained within a line. - * - * \param[in] c content of type CONTENT_TEXTPLAIN - * \param[in] x x ordinate of point - * \param[in] y y ordinate of point - * \param[in] dir direction of search if not within line - * \return byte offset of character containing (or nearest to) point - */ -size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir); - - -/** * Given a range of byte offsets within a UTF8 textplain content, * return a box that fully encloses the text * @@ -87,31 +58,6 @@ size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir); void textplain_coords_from_range(struct content *c, unsigned start, unsigned end, struct rect *r); -/** - * Return a pointer to the requested line of text. - * - * \param[in] c content of type CONTENT_TEXTPLAIN - * \param[in] lineno line number - * \param[out] poffset receives byte offset of line start within text - * \param[out] plen receives length of returned line - * \return pointer to text, or NULL if invalid line number - */ -char *textplain_get_line(struct content *c, unsigned lineno, - size_t *poffset, size_t *plen); - - -/** - * Find line number of byte in text - * - * Given a byte offset within the text, return the line number - * of the line containing that offset. - * - * \param[in] c content of type CONTENT_TEXTPLAIN - * \param[in] offset byte offset within textual representation - * \return line number, or -1 if offset invalid (larger than size) - */ -int textplain_find_line(struct content *c, unsigned offset); - /** * Return a pointer to the raw UTF-8 data, as opposed to the reformatted |