[pango/line-breaker: 26/33] Make PangoLayoutLine a boxed type
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/line-breaker: 26/33] Make PangoLayoutLine a boxed type
- Date: Tue, 25 Jan 2022 20:35:44 +0000 (UTC)
commit ae563e11bf20b458c9a5fdd89d7391b09d82d844
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jan 25 00:48:00 2022 -0500
Make PangoLayoutLine a boxed type
pango/pango-layout-line-private.h | 2 -
pango/pango-layout-line.c | 118 +++++++++++++++++++-------------------
pango/pango-layout-line.h | 8 ++-
pango/pango-lines.c | 18 ++----
pango/pango-types.h | 1 +
pango/pangocairo-render.c | 1 -
6 files changed, 73 insertions(+), 75 deletions(-)
---
diff --git a/pango/pango-layout-line-private.h b/pango/pango-layout-line-private.h
index 0132401f..4730a9a5 100644
--- a/pango/pango-layout-line-private.h
+++ b/pango/pango-layout-line-private.h
@@ -23,8 +23,6 @@ void line_data_clear (LineData *data);
struct _PangoLayoutLine
{
- GObject parent_instance;
-
PangoContext *context;
LineData *data;
diff --git a/pango/pango-layout-line.c b/pango/pango-layout-line.c
index 1a8d69bb..09a90955 100644
--- a/pango/pango-layout-line.c
+++ b/pango/pango-layout-line.c
@@ -58,43 +58,13 @@ line_data_unref (LineData *data)
g_rc_box_release_full (data, (GDestroyNotify) line_data_clear);
}
-/* }}} */
+/* }}} */
/* {{{ PangoLayoutLine implementation */
-struct _PangoLayoutLineClass
-{
- GObjectClass parent_class;
-};
-
-G_DEFINE_TYPE (PangoLayoutLine, pango_layout_line, G_TYPE_OBJECT)
-
-static void
-pango_layout_line_init (PangoLayoutLine *line)
-{
-}
-
-static void
-pango_layout_line_finalize (GObject *object)
-{
- PangoLayoutLine *line = PANGO_LAYOUT_LINE (object);
-
- g_object_unref (line->context);
-
- line_data_unref (line->data);
- g_slist_free_full (line->runs, (GDestroyNotify)pango_glyph_item_free);
+G_DEFINE_BOXED_TYPE (PangoLayoutLine, pango_layout_line,
+ pango_layout_line_copy, pango_layout_line_free);
- G_OBJECT_CLASS (pango_layout_line_parent_class)->finalize (object);
-}
-
-static void
-pango_layout_line_class_init (PangoLayoutLineClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->finalize = pango_layout_line_finalize;
-}
-
-/* }}} */
+/* }}} */
/* {{{ Justification */
static inline void
@@ -576,8 +546,7 @@ pango_layout_line_new (PangoContext *context,
{
PangoLayoutLine *line;
- line = g_object_new (PANGO_TYPE_LAYOUT_LINE, NULL);
-
+ line = g_new0 (PangoLayoutLine, 1);
line->context = g_object_ref (context);
line->data = line_data_ref (data);
@@ -615,6 +584,44 @@ pango_layout_line_index_to_run (PangoLayoutLine *line,
/* }}} */
/* {{{ Public API */
+
+PangoLayoutLine *
+pango_layout_line_copy (PangoLayoutLine *line)
+{
+ PangoLayoutLine *copy;
+
+ if (line == NULL)
+ return NULL;
+
+ copy = g_new0 (PangoLayoutLine, 1);
+ copy->context = g_object_ref (line->context);
+ copy->data = line_data_ref (line->data);
+ copy->start_index = line->start_index;
+ copy->length = line->length;
+ copy->start_offset = line->start_offset;
+ copy->n_chars = line->n_chars;
+ copy->wrapped = line->wrapped;
+ copy->ellipsized = line->ellipsized;
+ copy->hyphenated = line->hyphenated;
+ copy->justified = TRUE;
+ copy->starts_paragraph = line->starts_paragraph;
+ copy->ends_paragraph = line->ends_paragraph;
+ copy->has_extents = FALSE;
+ copy->direction = line->direction;
+ copy->runs = g_slist_copy_deep (line->runs, (GCopyFunc) pango_glyph_item_copy, NULL);
+
+ return copy;
+}
+
+void
+pango_layout_line_free (PangoLayoutLine *line)
+{
+ g_object_unref (line->context);
+ line_data_unref (line->data);
+ g_slist_free_full (line->runs, (GDestroyNotify)pango_glyph_item_free);
+ g_free (line);
+}
+
/* {{{ Simple getters */
/**
@@ -631,7 +638,7 @@ pango_layout_line_index_to_run (PangoLayoutLine *line,
GSList *
pango_layout_line_get_runs (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), NULL);
+ g_return_val_if_fail (line != NULL, NULL);
return line->runs;
}
@@ -657,7 +664,7 @@ pango_layout_line_get_text (PangoLayoutLine *line,
int *start_index,
int *length)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), NULL);
+ g_return_val_if_fail (line != NULL, NULL);
g_return_val_if_fail (start_index != NULL, NULL);
g_return_val_if_fail (length != NULL, NULL);
@@ -679,7 +686,7 @@ pango_layout_line_get_text (PangoLayoutLine *line,
int
pango_layout_line_get_start_index (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), 0);
+ g_return_val_if_fail (line != NULL, 0);
return line->start_index;
}
@@ -695,7 +702,7 @@ pango_layout_line_get_start_index (PangoLayoutLine *line)
int
pango_layout_line_get_length (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), 0);
+ g_return_val_if_fail (line != NULL, 0);
return line->length;
}
@@ -721,7 +728,7 @@ pango_layout_line_get_log_attrs (PangoLayoutLine *line,
int *start_offset,
int *n_attrs)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), NULL);
+ g_return_val_if_fail (line != NULL, NULL);
g_return_val_if_fail (start_offset != NULL, NULL);
g_return_val_if_fail (n_attrs != NULL, NULL);
@@ -742,7 +749,7 @@ pango_layout_line_get_log_attrs (PangoLayoutLine *line,
gboolean
pango_layout_line_is_wrapped (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
return line->wrapped;
}
@@ -758,7 +765,7 @@ pango_layout_line_is_wrapped (PangoLayoutLine *line)
gboolean
pango_layout_line_is_ellipsized (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
return line->ellipsized;
}
@@ -774,7 +781,7 @@ pango_layout_line_is_ellipsized (PangoLayoutLine *line)
gboolean
pango_layout_line_is_hyphenated (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
return line->hyphenated;
}
@@ -792,7 +799,7 @@ pango_layout_line_is_hyphenated (PangoLayoutLine *line)
gboolean
pango_layout_line_is_justified (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
return line->justified;
}
@@ -808,7 +815,7 @@ pango_layout_line_is_justified (PangoLayoutLine *line)
gboolean
pango_layout_line_is_paragraph_start (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
return line->starts_paragraph;
}
@@ -824,7 +831,7 @@ pango_layout_line_is_paragraph_start (PangoLayoutLine *line)
gboolean
pango_layout_line_is_paragraph_end (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
return line->ends_paragraph;
}
@@ -840,7 +847,7 @@ pango_layout_line_is_paragraph_end (PangoLayoutLine *line)
PangoDirection
pango_layout_line_get_resolved_direction (PangoLayoutLine *line)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT_LINE (line), PANGO_DIRECTION_LTR);
+ g_return_val_if_fail (line != NULL, PANGO_DIRECTION_LTR);
return line->direction;
}
@@ -871,6 +878,8 @@ pango_layout_line_justify (PangoLayoutLine *line,
int remaining_width;
PangoLayoutLine *copy;
+ g_return_val_if_fail (line != NULL, NULL);
+
remaining_width = width - pango_layout_line_compute_width (line);
if (remaining_width <= 0)
return line;
@@ -888,19 +897,12 @@ pango_layout_line_justify (PangoLayoutLine *line,
copy->ends_paragraph = line->ends_paragraph;
copy->has_extents = FALSE;
copy->direction = line->direction;
-
- /* Avoid a copy if we have exclusive ownership of line */
- if (G_OBJECT (line)->ref_count == 1)
- {
- copy->runs = line->runs;
- line->runs = NULL;
- }
- else
- copy->runs = g_slist_copy_deep (line->runs, (GCopyFunc) pango_glyph_item_copy, NULL);
+ copy->runs = line->runs;
+ line->runs = NULL;
justify_words (copy, &remaining_width);
- g_object_unref (line);
+ pango_layout_line_free (line);
return copy;
}
diff --git a/pango/pango-layout-line.h b/pango/pango-layout-line.h
index 7545e982..e45c8d10 100644
--- a/pango/pango-layout-line.h
+++ b/pango/pango-layout-line.h
@@ -7,10 +7,14 @@
G_BEGIN_DECLS
-#define PANGO_TYPE_LAYOUT_LINE pango_layout_line_get_type ()
+PANGO_AVAILABLE_IN_ALL
+GType pango_layout_line_get_type (void) G_GNUC_CONST;
+
+PANGO_AVAILABLE_IN_ALL
+PangoLayoutLine * pango_layout_line_copy (PangoLayoutLine *line);
PANGO_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (PangoLayoutLine, pango_layout_line, PANGO, LAYOUT_LINE, GObject);
+void pango_layout_line_free (PangoLayoutLine *line);
PANGO_AVAILABLE_IN_ALL
PangoLayoutLine * pango_layout_line_justify (PangoLayoutLine *line,
diff --git a/pango/pango-lines.c b/pango/pango-lines.c
index b4ea5ccd..ac447e91 100644
--- a/pango/pango-lines.c
+++ b/pango/pango-lines.c
@@ -69,7 +69,7 @@ pango_lines_finalize (GObject *object)
for (int i = 0; i < lines->lines->len; i++)
{
Line *line = &g_array_index (lines->lines, Line, i);
- g_object_unref (line->line);
+ pango_layout_line_free (line->line);
}
g_array_free (lines->lines, TRUE);
@@ -104,10 +104,10 @@ compare_cursor (gconstpointer v1,
}
static void
-pango_layout_line_get_cursors (PangoLines *lines,
- PangoLayoutLine *line,
- gboolean strong,
- GArray *cursors)
+pango_layout_line_get_cursors (PangoLines *lines,
+ PangoLayoutLine *line,
+ gboolean strong,
+ GArray *cursors)
{
const char *start, *end;
int start_offset;
@@ -158,7 +158,7 @@ pango_layout_line_get_cursors (PangoLines *lines,
}
/* }}} */
-/* {{{ Public API */
+ /* {{{ Public API */
/**
* pango_lines_new:
@@ -580,9 +580,6 @@ pango_lines_get_x_ranges (PangoLines *lines,
int accumulated_width;
g_return_if_fail (PANGO_IS_LINES (lines));
- g_return_if_fail (PANGO_IS_LAYOUT_LINE (line));
- g_return_if_fail (start_line == NULL || PANGO_IS_LAYOUT_LINE (start_line));
- g_return_if_fail (end_line == NULL || PANGO_IS_LAYOUT_LINE (end_line));
g_return_if_fail (ranges != NULL);
g_return_if_fail (n_ranges != NULL);
@@ -845,7 +842,6 @@ pango_lines_index_to_pos (PangoLines *lines,
int x_offset, y_offset;
g_return_if_fail (PANGO_IS_LINES (lines));
- g_return_if_fail (line == NULL || PANGO_IS_LAYOUT_LINE (line));
g_return_if_fail (idx >= 0);
g_return_if_fail (pos != NULL);
@@ -949,7 +945,6 @@ pango_lines_get_cursor_pos (PangoLines *lines,
PangoLayoutLine *l;
g_return_if_fail (PANGO_IS_LINES (lines));
- g_return_if_fail (line == NULL || PANGO_IS_LAYOUT_LINE (line));
l = line;
pango_lines_index_to_line (lines, idx, &l, NULL, &x_offset, &y_offset);
@@ -1007,7 +1002,6 @@ pango_lines_get_caret_pos (PangoLines *lines,
int x_offset, y_offset;
g_return_if_fail (PANGO_IS_LINES (lines));
- g_return_if_fail (line == NULL || PANGO_IS_LAYOUT_LINE (line));
pango_lines_index_to_line (lines, idx, &line, NULL, &x_offset, &y_offset);
diff --git a/pango/pango-types.h b/pango/pango-types.h
index 82892928..b4114385 100644
--- a/pango/pango-types.h
+++ b/pango/pango-types.h
@@ -55,6 +55,7 @@ typedef guint32 PangoGlyph;
typedef struct _PangoLines PangoLines;
typedef struct _PangoLayoutRun PangoLayoutRun;
+typedef struct _PangoLayoutLine PangoLayoutLine;
typedef struct _PangoLayoutIter PangoLayoutIter;
/**
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index 361fc563..e5417825 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -1247,7 +1247,6 @@ pango_cairo_layout_line_path (cairo_t *cr,
PangoLayoutLine *line)
{
g_return_if_fail (cr != NULL);
- g_return_if_fail (PANGO_IS_LAYOUT_LINE (line));
_pango_cairo_do_layout_line (cr, line, TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]