diff options
author | Christian Persch <chpe@src.gnome.org> | 2018-10-19 21:07:36 +0200 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2018-10-19 21:07:36 +0200 |
commit | 92a478f926ded10dc15726e31998d041d6ff7794 (patch) | |
tree | 9bdf4b927ae62cb2d255e4aa6b0864984c53bceb | |
parent | 17c72f0560bf079cbd0e6df5dd3445cb8f05660a (diff) |
Hide internal symbols
Use hidden visibility by default and make only the public API
symbols visible.
https://gitlab.freedesktop.org/libspectre/libspectre/issues/30
-rw-r--r-- | configure.ac | 33 | ||||
-rw-r--r-- | libspectre/Makefile.am | 3 | ||||
-rw-r--r-- | libspectre/spectre-document.h | 20 | ||||
-rw-r--r-- | libspectre/spectre-exporter.h | 6 | ||||
-rw-r--r-- | libspectre/spectre-macros.h | 8 | ||||
-rw-r--r-- | libspectre/spectre-page.h | 8 | ||||
-rw-r--r-- | libspectre/spectre-render-context.h | 14 | ||||
-rw-r--r-- | libspectre/spectre-status.h | 1 | ||||
-rw-r--r-- | test/Makefile.am | 12 |
9 files changed, 102 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index c1486df..ac040c3 100644 --- a/configure.ac +++ b/configure.ac @@ -292,6 +292,39 @@ if test "x$spectre_cv_va_val_copy" = "xno"; then AC_DEFINE(SPECTRE_VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values]) fi +dnl Check for -fvisibility=hidden to determine if we can do GNU-style +dnl visibility attributes for symbol export control +dnl +VISIBILITY_CFLAGS="" +case "$host" in + *-*-mingw*) + dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport) + AC_DEFINE([SPECTRE_PUBLIC], [__attribute__((visibility("default"))) __declspec(dllexport) extern], + [defines how to decorate public symbols while building]) + CFLAGS="${CFLAGS} -fvisibility=hidden" + ;; + *) + dnl on other compilers, check if we can do -fvisibility=hidden + SAVED_CFLAGS="${CFLAGS}" + CFLAGS="-fvisibility=hidden" + AC_MSG_CHECKING([for -fvisibility=hidden compiler flag]) + AC_TRY_COMPILE([], [return 0], + AC_MSG_RESULT(yes) + enable_fvisibility_hidden=yes, + AC_MSG_RESULT(no) + enable_fvisibility_hidden=no) + CFLAGS="${SAVED_CFLAGS}" + + AS_IF([test "${enable_fvisibility_hidden}" = "yes"], [ + AC_DEFINE([SPECTRE_PUBLIC], [__attribute__((visibility("default"))) extern], + [defines how to decorate public symbols while building]) + VISIBILITY_CFLAGS="-fvisibility=hidden" + ], + [AC_DEFINE([SPECTRE_PUBLIC],[extern])]) + ;; +esac +AC_SUBST([VISIBILITY_CFLAGS]) + AC_OUTPUT([ Makefile Doxyfile diff --git a/libspectre/Makefile.am b/libspectre/Makefile.am index b2a6b38..3136a6c 100644 --- a/libspectre/Makefile.am +++ b/libspectre/Makefile.am @@ -44,5 +44,8 @@ libspectre_la_SOURCES = \ libspectre_la_CPPFLAGS = \ $(SPECTRE_CFLAGS) +libspectre_la_CFLAGS = \ + $(VISIBILITY_CFLAGS) + libspectre_la_LIBADD = $(LIB_GS) libspectre_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined diff --git a/libspectre/spectre-document.h b/libspectre/spectre-document.h index 4b08298..40cccb4 100644 --- a/libspectre/spectre-document.h +++ b/libspectre/spectre-document.h @@ -31,6 +31,7 @@ SPECTRE_BEGIN_DECLS typedef struct SpectreDocument SpectreDocument; /*! Creates a document */ +SPECTRE_PUBLIC SpectreDocument *spectre_document_new (void); /*! Loads a the given file into the document. This function can fail @@ -38,29 +39,34 @@ SpectreDocument *spectre_document_new (void); @param filename the file to loa @see spectre_document_status */ +SPECTRE_PUBLIC void spectre_document_load (SpectreDocument *document, const char *filename); /*! Returns the document status @param document the document whose status will be returned */ +SPECTRE_PUBLIC SpectreStatus spectre_document_status (SpectreDocument *document); /*! Frees the document @param document the document that will be freed */ +SPECTRE_PUBLIC void spectre_document_free (SpectreDocument *document); /*! Returns the number of pages of the document. This function can fail @param document the document whose pages number will be returned @see spectre_document_status */ +SPECTRE_PUBLIC unsigned int spectre_document_get_n_pages (SpectreDocument *document); /*! Returns the orientation of the document. This function can fail @param document the document whose orientation will be returned @see spectre_document_status */ +SPECTRE_PUBLIC SpectreOrientation spectre_document_get_orientation (SpectreDocument *document); /*! Returns the title of the document. It returns a null const char * if @@ -68,6 +74,7 @@ SpectreOrientation spectre_document_get_orientation (SpectreDocument *documen @param document the document whose title will be returned @see spectre_document_status */ +SPECTRE_PUBLIC const char *spectre_document_get_title (SpectreDocument *document); /*! Returns the creator of the document. It returns a null const char * if @@ -75,6 +82,7 @@ const char *spectre_document_get_title (SpectreDocument *documen @param document the document whose creator will be returned @see spectre_document_status */ +SPECTRE_PUBLIC const char *spectre_document_get_creator (SpectreDocument *document); /*! Returns the for of the document. It returns a null const char * if @@ -82,6 +90,7 @@ const char *spectre_document_get_creator (SpectreDocument *documen @param document the document whose for will be returned @see spectre_document_status */ +SPECTRE_PUBLIC const char *spectre_document_get_for (SpectreDocument *document); /*! Returns the creation date of the document. The date is copied verbatim from @@ -90,18 +99,21 @@ const char *spectre_document_get_for (SpectreDocument *documen @param document the document whose creation date will be returned @see spectre_document_status */ +SPECTRE_PUBLIC const char *spectre_document_get_creation_date (SpectreDocument *document); /*! Returns the format of the document. This function can fail @param document the document whose format will be returned @see spectre_document_status */ +SPECTRE_PUBLIC const char *spectre_document_get_format (SpectreDocument *document); /*! Returns if the document is a Encapsulated PostScript file. This function can fail @param document the document to query @see spectre_document_status */ +SPECTRE_PUBLIC int spectre_document_is_eps (SpectreDocument *document); /*! Returns the PostScript language level of the document. It returns 0 if no @@ -109,6 +121,7 @@ int spectre_document_is_eps (SpectreDocument *documen @param document the document whose language level will be returned @see spectre_document_status */ +SPECTRE_PUBLIC unsigned int spectre_document_get_language_level (SpectreDocument *document); /*! Returns a page of the document. This function can fail @@ -116,6 +129,7 @@ unsigned int spectre_document_get_language_level (SpectreDocument *documen @param page_index the page index to get. First page has index 0. @see spectre_document_status */ +SPECTRE_PUBLIC SpectrePage *spectre_document_get_page (SpectreDocument *document, unsigned int page_index); @@ -124,6 +138,7 @@ SpectrePage *spectre_document_get_page (SpectreDocument *documen @param label the label of the page to get. @see spectre_document_status */ +SPECTRE_PUBLIC SpectrePage *spectre_document_get_page_by_label (SpectreDocument *document, const char *label); @@ -137,6 +152,7 @@ SpectrePage *spectre_document_get_page_by_label (SpectreDocument *documen @row_length the length of an image row will be returned here @see spectre_document_render_full */ +SPECTRE_PUBLIC void spectre_document_render_full (SpectreDocument *document, SpectreRenderContext *rc, unsigned char **page_data, @@ -153,6 +169,7 @@ void spectre_document_render_full (SpectreDocument *do @row_length the length of an image row will be returned here @see spectre_document_render_full */ +SPECTRE_PUBLIC void spectre_document_render (SpectreDocument *document, unsigned char **page_data, int *row_length); @@ -163,6 +180,7 @@ void spectre_document_render (SpectreDocument *do @width the page width will be returned here, or NULL @height the page height will be returned here, or NULL */ +SPECTRE_PUBLIC void spectre_document_get_page_size (SpectreDocument *document, int *width, int *height); @@ -172,6 +190,7 @@ void spectre_document_get_page_size (SpectreDocument *do @param filename the path where document will be saved @see spectre_document_status */ +SPECTRE_PUBLIC void spectre_document_save (SpectreDocument *document, const char *filename); /* Save document as a pdf document. This function can fail @@ -179,6 +198,7 @@ void spectre_document_save (SpectreDocument *documen @param filename the path where document will be saved as pdf @see spectre_document_status */ +SPECTRE_PUBLIC void spectre_document_save_to_pdf (SpectreDocument *document, const char *filename); SPECTRE_END_DECLS diff --git a/libspectre/spectre-exporter.h b/libspectre/spectre-exporter.h index aed8c7b..96509d3 100644 --- a/libspectre/spectre-exporter.h +++ b/libspectre/spectre-exporter.h @@ -34,16 +34,20 @@ typedef enum { typedef struct SpectreExporter SpectreExporter; +SPECTRE_PUBLIC SpectreExporter *spectre_exporter_new (SpectreDocument *document, SpectreExporterFormat format); +SPECTRE_PUBLIC void spectre_exporter_free (SpectreExporter *exporter); +SPECTRE_PUBLIC SpectreStatus spectre_exporter_begin (SpectreExporter *exporter, const char *filename); +SPECTRE_PUBLIC SpectreStatus spectre_exporter_do_page (SpectreExporter *exporter, unsigned int page_index); +SPECTRE_PUBLIC SpectreStatus spectre_exporter_end (SpectreExporter *exporter); - SPECTRE_END_DECLS #endif /* SPECTRE_EXPORTER_H */ diff --git a/libspectre/spectre-macros.h b/libspectre/spectre-macros.h index 65152bc..71e70d2 100644 --- a/libspectre/spectre-macros.h +++ b/libspectre/spectre-macros.h @@ -44,4 +44,12 @@ # endif /* !__cplusplus */ #endif +#if defined(_WIN32) +# define SPECTRE_PUBLIC __declspec(dllexport) +#elif defined(__GNUC__) +# define SPECTRE_PUBLIC __attribute__((visibility("default"))) extern +#else +# define SPECTRE_PUBLIC +#endif + #endif /* SPECTRE_MACROS_H */ diff --git a/libspectre/spectre-page.h b/libspectre/spectre-page.h index 3b85d10..9d5f107 100644 --- a/libspectre/spectre-page.h +++ b/libspectre/spectre-page.h @@ -43,26 +43,31 @@ typedef struct SpectrePage SpectrePage; /*! Returns the status of the given page @param page The page whose status will be returned */ +SPECTRE_PUBLIC SpectreStatus spectre_page_status (SpectrePage *page); /*! Frees the memory of the given page @param page The page whose memory will be freed */ +SPECTRE_PUBLIC void spectre_page_free (SpectrePage *page); /*! Returns the index of the page inside the document. First page has index 0 @param page The page whose index will be returned */ +SPECTRE_PUBLIC unsigned int spectre_page_get_index (SpectrePage *page); /*! Returns the label of the page inside the document. @param page The page whose label will be returned */ +SPECTRE_PUBLIC const char *spectre_page_get_label (SpectrePage *page); /*! Returns the orientation of the page @param page The page whose orientation will be returned */ +SPECTRE_PUBLIC SpectreOrientation spectre_page_get_orientation (SpectrePage *page); /*! Returns the size of the page. It always returns the page size according to @@ -72,6 +77,7 @@ SpectreOrientation spectre_page_get_orientation (SpectrePage *page); @param height The page height will be returned here, or NULL @see spectre_page_get_orientation */ +SPECTRE_PUBLIC void spectre_page_get_size (SpectrePage *page, int *width, int *height); @@ -85,6 +91,7 @@ void spectre_page_get_size (SpectrePage *page, happen that row_length is different than width * 4 @see spectre_page_status */ +SPECTRE_PUBLIC void spectre_page_render (SpectrePage *page, SpectreRenderContext *rc, unsigned char **page_data, @@ -103,6 +110,7 @@ void spectre_page_render (SpectrePage *page, happen that row_length is different than width * 4 @see spectre_page_status */ +SPECTRE_PUBLIC void spectre_page_render_slice (SpectrePage *page, SpectreRenderContext *rc, int x, diff --git a/libspectre/spectre-render-context.h b/libspectre/spectre-render-context.h index e1e7750..9508963 100644 --- a/libspectre/spectre-render-context.h +++ b/libspectre/spectre-render-context.h @@ -29,11 +29,13 @@ SPECTRE_BEGIN_DECLS typedef struct SpectreRenderContext SpectreRenderContext; /*! Creates a rendering context */ +SPECTRE_PUBLIC SpectreRenderContext *spectre_render_context_new (void); /*! Frees a rendering context @param rc The rendering context to free */ +SPECTRE_PUBLIC void spectre_render_context_free (SpectreRenderContext *rc); /*! Sets the scale. The default is 1 @@ -41,6 +43,7 @@ void spectre_render_context_free (SpectreRend @param x_scale The scale factor for the X dimension to use when rendering. 2 is twice as big @param y_scale The scale factor for the Y dimension to use when rendering. 2 is twice as big */ +SPECTRE_PUBLIC void spectre_render_context_set_scale (SpectreRenderContext *rc, double x_scale, double y_scale); @@ -50,6 +53,7 @@ void spectre_render_context_set_scale (SpectreRend @param x_scale The scale factor for the X dimension will be stored here, or NULL @param y_scale The scale factor for the Y dimension will be stored here, or NULL */ +SPECTRE_PUBLIC void spectre_render_context_get_scale (SpectreRenderContext *rc, double *x_scale, double *y_scale); @@ -58,12 +62,14 @@ void spectre_render_context_get_scale (SpectreRend @param rc The rendering context to modify @param rotation The rotation to use when rendering. Usually 0, 90, 180 or 270 */ +SPECTRE_PUBLIC void spectre_render_context_set_rotation (SpectreRenderContext *rc, unsigned int rotation); /*! Gets the rotation @param rc The rendering context to query */ +SPECTRE_PUBLIC unsigned int spectre_render_context_get_rotation (SpectreRenderContext *rc); /*! Sets the resolution. The default is 72 for both directions @@ -71,6 +77,7 @@ unsigned int spectre_render_context_get_rotation (SpectreRend @param x_dpi the horizontal resolution to set @param y_dpi the vertical resolution to set */ +SPECTRE_PUBLIC void spectre_render_context_set_resolution (SpectreRenderContext *rc, double x_dpi, double y_dpi); @@ -80,6 +87,7 @@ void spectre_render_context_set_resolution (SpectreRend @param x_dpi the horizontal resolution will be stored here, or NULL @param y_dpi the vertical resolution will be stored here, or NULL */ +SPECTRE_PUBLIC void spectre_render_context_get_resolution (SpectreRenderContext *rc, double *x_dpi, double *y_dpi); @@ -93,6 +101,7 @@ void spectre_render_context_get_resolution (SpectreRend @param width the width of the page @param height the height of the page */ +SPECTRE_PUBLIC void spectre_render_context_set_page_size (SpectreRenderContext *rc, int width, int height); @@ -102,6 +111,7 @@ void spectre_render_context_set_page_size (SpectreRend @param width the width of the page will be stored here, or NULL @param height the height of the page will be stored here, or NULL */ +SPECTRE_PUBLIC void spectre_render_context_get_page_size (SpectreRenderContext *rc, int *width, int *height); @@ -110,12 +120,14 @@ void spectre_render_context_get_page_size (SpectreRend @param rc The rendering context to modify @param use_platform_fonts should platform fonts be used when rendering? */ +SPECTRE_PUBLIC void spectre_render_context_set_use_platform_fonts (SpectreRenderContext *rc, int use_platform_fonts); /*! Gets whether to use the platform fonts when rendering or not @param rc The rendering context to query */ +SPECTRE_PUBLIC int spectre_render_context_get_use_platform_fonts (SpectreRenderContext *rc); /*! Sets the antialias options for graphics and texts. The default is 4 for graphics and 2 for text @@ -125,6 +137,7 @@ int spectre_render_context_get_use_platform_fonts (SpectreRend @param text_bits The number of antialias bits to use for text. Typically 2 for antialias and 1 for no antialias */ +SPECTRE_PUBLIC void spectre_render_context_set_antialias_bits (SpectreRenderContext *rc, int graphics_bits, int text_bits); @@ -134,6 +147,7 @@ void spectre_render_context_set_antialias_bits (SpectreRend @param graphics_bits The number of antialias bits to use for graphics will be stored here @param text_bits The number of antialias bits to use for text will be stored here */ +SPECTRE_PUBLIC void spectre_render_context_get_antialias_bits (SpectreRenderContext *rc, int *graphics_bits, int *text_bits); diff --git a/libspectre/spectre-status.h b/libspectre/spectre-status.h index 58918cd..d26d7a6 100644 --- a/libspectre/spectre-status.h +++ b/libspectre/spectre-status.h @@ -51,6 +51,7 @@ typedef enum _SpectreStatus { /*! Gets a textual description of the given status @param status the status whose textual description will be returned */ +SPECTRE_PUBLIC const char *spectre_status_to_string (SpectreStatus status); SPECTRE_END_DECLS diff --git a/test/Makefile.am b/test/Makefile.am index f078626..1606541 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,9 @@ noinst_PROGRAMS = spectre-test parser-test -spectre_test_SOURCES = spectre-test.c +spectre_test_SOURCES = \ + spectre-test.c \ + $(top_srcdir)/libspectre/spectre-utils.c \ + $(top_srcdir)/libspectre/spectre-utils.h spectre_test_CPPFLAGS = \ -I$(top_srcdir)/libspectre \ @@ -11,7 +14,12 @@ spectre_test_LDADD = \ $(top_builddir)/libspectre/libspectre.la \ $(CAIRO_LIBS) -parser_test_SOURCES = parser-test.c +parser_test_SOURCES = \ + parser-test.c \ + $(top_srcdir)/libspectre/ps.c \ + $(top_srcdir)/libspectre/ps.h \ + $(top_srcdir)/libspectre/spectre-utils.c \ + $(top_srcdir)/libspectre/spectre-utils.h parser_test_CPPFLAGS = \ -I$(top_srcdir)/libspectre \ |