]> gitweb.michael.orlitzky.com - libsvgtiny-pixbuf.git/commitdiff
io-svg.c: try to use stupid gtypes consistently.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Aug 2023 17:27:07 +0000 (13:27 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Aug 2023 17:27:07 +0000 (13:27 -0400)
io-svg.c

index d0c2a1b7b654d5c818440b6a4dd41b43f03f9ee2..09b70af7e43cea233227b0cca0ba07ef1d23da8d 100644 (file)
--- a/io-svg.c
+++ b/io-svg.c
@@ -33,7 +33,7 @@ typedef struct {
   gpointer                    user_data;
 
   /* The SVG "file" that we're building in memory. */
-  char*                       svg_data;
+  gchar*                      svg_data;
 
   /* How far into svg_data are we? This should always point to the
      next empty byte. If (for example) svg_data_size is 2, then
@@ -118,10 +118,10 @@ static void render_path(cairo_t* cr, shape_t* path) {
  *   returned; if not, @c NULL is returned. You are expected to @c
  *   svgtiny_free the result if it is valid.
  */
-static diagram_t* svgtiny_diagram_from_buffer(char* buffer,
-                                              size_t bytecount,
-                                              int width,
-                                              int height,
+static diagram_t* svgtiny_diagram_from_buffer(gchar* buffer,
+                                              gsize bytecount,
+                                              guint width,
+                                              guint height,
                                               GError** error) {
   diagram_t* diagram;
   svgtiny_code code;
@@ -135,7 +135,13 @@ static diagram_t* svgtiny_diagram_from_buffer(char* buffer,
     return NULL;
   }
 
-  code = svgtiny_parse(diagram, buffer, bytecount, "", width, height);
+  g_assert((int)width >= 0);
+  g_assert((int)height >= 0);
+  code = svgtiny_parse(diagram,
+                      buffer,
+                      bytecount, "",
+                      (int)width,
+                      (int)height);
 
   switch(code) {
     case svgtiny_OK:
@@ -277,8 +283,8 @@ static cairo_t* cairo_context_from_diagram(diagram_t* diagram) {
  * @return If successful, a valid pointer to a @c GdkPixbuf is
  *   returned; if not, @c NULL is returned and @c error is populated.
  */
-static GdkPixbuf* gdk_pixbuf_from_svg_buffer(char* buffer,
-                                             size_t bytecount,
+static GdkPixbuf* gdk_pixbuf_from_svg_buffer(gchar* buffer,
+                                             gsize bytecount,
                                              GError** error) {
   diagram_t* diagram;
   cairo_t* cr = 0;
@@ -419,12 +425,12 @@ static void emit_prepared(SvgTinyContext* context, GdkPixbuf* pixbuf) {
  * processed. If no replacements were made, the result will be @c
  * NULL; otherwise, you are expected to @c free it when you are done.
  */
-static char* process_gtk_symbolic_svg_xinclude(const char* buffer,
-                                              size_t buf_size,
-                                              size_t* new_size) {
-  char* xi_start;
-  char* xi;
-  char* xi_stop;
+static gchar* process_gtk_symbolic_svg_xinclude(const gchar* buffer,
+                                                gsize buf_size,
+                                               gsize* new_size) {
+  gchar* xi_start;
+  gchar* xi;
+  gchar* xi_stop;
 
   xi_start = g_strstr_len(buffer, buf_size, XI_SIGNATURE);
   if (xi_start == NULL) {
@@ -481,10 +487,10 @@ static char* process_gtk_symbolic_svg_xinclude(const char* buffer,
    * started at, say, position three, then this would compute a size
    * of three. Which is correct: we want to retain buffer[0],
    * buffer[1], and buffer[2]. */
-  size_t keep_size = xi_start - buffer;
+  gsize keep_size = xi_start - buffer;
   *new_size = keep_size + decoded_size;
 
-  char* result = g_malloc(*new_size);
+  gchar* result = g_malloc(*new_size);
   memcpy(result, buffer, keep_size);
   memcpy(result+keep_size, decoded, decoded_size);
   g_free(decoded);
@@ -502,10 +508,10 @@ static gboolean gdk_pixbuf_stop_load(gpointer data, GError **error) {
   /* If we're inside of gtk-encode-symbolic-svg right now, we need to
      process the insane librsvg-specific XInclude directive it hands
      us before proceeding. */
-  size_t newsize;
-  char* newdata = process_gtk_symbolic_svg_xinclude(context->svg_data,
-                                                   context->svg_data_size,
-                                                   &newsize);
+  gsize newsize;
+  gchar* newdata = process_gtk_symbolic_svg_xinclude(context->svg_data,
+                                                     context->svg_data_size,
+                                                     &newsize);
   if (newdata != NULL) {
     g_free(context->svg_data);
     context->svg_data = newdata;