r10086 jmb - in /branches/jmb/new-cache/render: textplain.c textplain.h

netsurf at semichrome.net netsurf at semichrome.net
Sun Feb 28 15:30:02 GMT 2010


Author: jmb
Date: Sun Feb 28 09:30:02 2010
New Revision: 10086

URL: http://source.netsurf-browser.org?rev=10086&view=rev
Log:
Make textplain APIs called from desktop/ and above take hlcache_handle * instead of struct content *

Modified:
    branches/jmb/new-cache/render/textplain.c
    branches/jmb/new-cache/render/textplain.h

Modified: branches/jmb/new-cache/render/textplain.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/render/textplain.c?rev=10086&r1=10085&r2=10086&view=diff
==============================================================================
--- branches/jmb/new-cache/render/textplain.c (original)
+++ branches/jmb/new-cache/render/textplain.c Sun Feb 28 09:30:02 2010
@@ -29,6 +29,7 @@
 #include <math.h>
 #include <iconv.h>
 #include "content/content_protected.h"
+#include "content/hlcache.h"
 #include "css/css.h"
 #include "css/utils.h"
 #include "desktop/gui.h"
@@ -472,22 +473,30 @@
 /**
  * Retrieve number of lines in content
  *
- * \param c  Content to retrieve line count from
+ * \param h  Content to retrieve line count from
  * \return Number of lines
  */
-unsigned long textplain_line_count(struct content *c)
-{
+unsigned long textplain_line_count(hlcache_handle *h)
+{
+	struct content *c = hlcache_handle_get_content(h);
+
+	assert(c != NULL);
+
 	return c->data.textplain.physical_line_count;
 }
 
 /**
  * Retrieve the size (in bytes) of text data
  *
- * \param c  Content to retrieve size of
+ * \param h  Content to retrieve size of
  * \return Size, in bytes, of data
  */
-size_t textplain_size(struct content *c)
-{
+size_t textplain_size(hlcache_handle *h)
+{
+	struct content *c = hlcache_handle_get_content(h);
+
+	assert(c != NULL);
+
 	return c->data.textplain.utf8_data_size;
 }
 
@@ -497,15 +506,16 @@
  * which to search (-1 = above-left, +1 = below-right) if the co-ordinates are not
  * contained within a line.
  *
- * \param  c     content of type CONTENT_TEXTPLAIN
+ * \param  h     content of type CONTENT_TEXTPLAIN
  * \param  x     x ordinate of point
  * \param  y     y ordinate of point
  * \param  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)
-{
+size_t textplain_offset_from_coords(hlcache_handle *h, int x, int y, int dir)
+{
+	struct content *c = hlcache_handle_get_content(h);
 	float line_height = textplain_line_height();
 	struct textplain_line *line;
 	const char *text;
@@ -513,6 +523,7 @@
 	size_t length;
 	int idx;
 
+	assert(c != NULL);
 	assert(c->type == CONTENT_TEXTPLAIN);
 
 	y = (int)((float)(y - MARGIN) / line_height);
@@ -576,18 +587,23 @@
  * Given a byte offset within the text, return the line number
  * of the line containing that offset (or -1 if offset invalid)
  *
- * \param  c       content of type CONTENT_TEXTPLAIN
+ * \param  h       content of type CONTENT_TEXTPLAIN
  * \param  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)
-{
-	struct textplain_line *line = c->data.textplain.physical_line;
-	int nlines = c->data.textplain.physical_line_count;
+int textplain_find_line(hlcache_handle *h, unsigned offset)
+{
+	struct content *c = hlcache_handle_get_content(h);
+	struct textplain_line *line;
+	int nlines;
 	int lineno = 0;
 
+	assert(c != NULL);
 	assert(c->type == CONTENT_TEXTPLAIN);
+
+	line = c->data.textplain.physical_line;
+	nlines = c->data.textplain.physical_line_count;
 
 	if (offset > c->data.textplain.utf8_data_size)
 		return -1;
@@ -646,30 +662,33 @@
  * Given a range of byte offsets within a UTF8 textplain content,
  * return a box that fully encloses the text
  *
- * \param  c      content of type CONTENT_TEXTPLAIN
+ * \param  h      content of type CONTENT_TEXTPLAIN
  * \param  start  byte offset of start of text range
  * \param  end    byte offset of end
  * \param  r      rectangle to be completed
  */
 
-void textplain_coords_from_range(struct content *c, unsigned start, unsigned end,
-		struct rect *r)
-{
+void textplain_coords_from_range(hlcache_handle *h, unsigned start, 
+		unsigned end, struct rect *r)
+{
+	struct content *c = hlcache_handle_get_content(h);
 	float line_height = textplain_line_height();
-	char *utf8_data = c->data.textplain.utf8_data;
+	char *utf8_data;
 	struct textplain_line *line;
 	unsigned lineno = 0;
 	unsigned nlines;
 
+	assert(c != NULL);
 	assert(c->type == CONTENT_TEXTPLAIN);
 	assert(start <= end);
 	assert(end <= c->data.textplain.utf8_data_size);
 
+	utf8_data = c->data.textplain.utf8_data;
 	nlines = c->data.textplain.physical_line_count;
 	line = c->data.textplain.physical_line;
 
 	/* find start */
-	lineno = textplain_find_line(c, start);
+	lineno = textplain_find_line(h, start);
 
 	r->y0 = (int)(MARGIN + lineno * line_height);
 
@@ -678,7 +697,7 @@
 			forwards most of the time */
 
 		/* find end */
-		lineno = textplain_find_line(c, end);
+		lineno = textplain_find_line(h, end);
 
 		r->x0 = 0;
 		r->x1 = c->data.textplain.formatted_width;
@@ -701,18 +720,20 @@
 /**
  * Return a pointer to the requested line of text.
  *
- * \param  c		    content of type CONTENT_TEXTPLAIN
+ * \param  h		    content of type CONTENT_TEXTPLAIN
  * \param  lineno	    line number
  * \param  poffset	    receives byte offset of line start within text
  * \param  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,
+char *textplain_get_line(hlcache_handle *h, unsigned lineno,
 		size_t *poffset, size_t *plen)
 {
+	struct content *c = hlcache_handle_get_content(h);
 	struct textplain_line *line;
 
+	assert(c != NULL);
 	assert(c->type == CONTENT_TEXTPLAIN);
 
 	if (lineno >= c->data.textplain.physical_line_count)
@@ -730,19 +751,23 @@
  * text to fit the window width. Thus only hard newlines are preserved
  * in the saved/copied text of a selection.
  *
- * \param  c		    content of type CONTENT_TEXTPLAIN
+ * \param  h		    content of type CONTENT_TEXTPLAIN
  * \param  start	    starting byte offset within UTF-8 text
  * \param  end		    ending byte offset
  * \param  plen		    receives validated length
  * \return pointer to text, or NULL if no text
  */
 
-char *textplain_get_raw_data(struct content *c, unsigned start, unsigned end,
+char *textplain_get_raw_data(hlcache_handle *h, unsigned start, unsigned end,
 		size_t *plen)
 {
-	size_t utf8_size = c->data.textplain.utf8_data_size;
-
+	struct content *c = hlcache_handle_get_content(h);
+	size_t utf8_size;
+
+	assert(c != NULL);
 	assert(c->type == CONTENT_TEXTPLAIN);
+
+	utf8_size = c->data.textplain.utf8_data_size;
 
 	/* any text at all? */
 	if (!utf8_size) return NULL;

Modified: branches/jmb/new-cache/render/textplain.h
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/render/textplain.h?rev=10086&r1=10085&r2=10086&view=diff
==============================================================================
--- branches/jmb/new-cache/render/textplain.h (original)
+++ branches/jmb/new-cache/render/textplain.h Sun Feb 28 09:30:02 2010
@@ -28,6 +28,7 @@
 #include <iconv.h>
 
 struct content;
+struct hlcache_handle;
 
 struct textplain_line {
 	size_t	start;
@@ -57,16 +58,17 @@
 		float scale, colour background_colour);
 
 /* access to lines for text selection and searching */
-unsigned long textplain_line_count(struct content *c);
-size_t textplain_size(struct content *c);
+unsigned long textplain_line_count(struct hlcache_handle *h);
+size_t textplain_size(struct hlcache_handle *h);
 
-size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir);
-void textplain_coords_from_range(struct content *c,
+size_t textplain_offset_from_coords(struct hlcache_handle *h, int x, int y, 
+		int dir);
+void textplain_coords_from_range(struct hlcache_handle *h,
 		unsigned start, unsigned end, struct rect *r);
-char *textplain_get_line(struct content *c, unsigned lineno,
+char *textplain_get_line(struct hlcache_handle *h, unsigned lineno,
 		size_t *poffset, size_t *plen);
-int textplain_find_line(struct content *c, unsigned offset);
-char *textplain_get_raw_data(struct content *c,
+int textplain_find_line(struct hlcache_handle *h, unsigned offset);
+char *textplain_get_raw_data(struct hlcache_handle *h,
 		unsigned start, unsigned end, size_t *plen);
 
 #endif




More information about the netsurf-commits mailing list