[evince] font properties: say whether fonts are pdf standard
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] font properties: say whether fonts are pdf standard
- Date: Sat, 5 Jan 2013 12:12:08 +0000 (UTC)
commit bda8ab9cfb8c1b808ab22c5059e530b10ffed0e0
Author: Alban Crequy <alban crequy collabora co uk>
Date: Tue Nov 27 18:07:57 2012 +0000
font properties: say whether fonts are pdf standard
In the font property dialog, say for each non-embedded font whether it is one
of the 14 standard fonts.
Backends can also implement get_fonts_summary() to return a summary line to
display before the tree view to say whether there is any non-embedded and
non-standard font.
https://bugzilla.gnome.org/show_bug.cgi?id=527222
backend/pdf/ev-poppler.cc | 85 +++++++++++++++++++++++++++++++++++---
libdocument/ev-document-fonts.c | 11 +++++
libdocument/ev-document-fonts.h | 26 ++++++-----
shell/ev-properties-fonts.c | 24 ++++++++++-
4 files changed, 126 insertions(+), 20 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 6f29caa..e8f36c6 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -106,6 +106,7 @@ struct _PdfDocument
PopplerFontInfo *font_info;
PopplerFontsIter *fonts_iter;
int fonts_scanned_pages;
+ gboolean missing_fonts;
PdfPrintContext *print_ctx;
@@ -1047,6 +1048,54 @@ font_type_to_string (PopplerFontType type)
}
}
+static gboolean
+is_standard_font (const gchar *name, PopplerFontType type)
+{
+ /* list borrowed from Poppler: poppler/GfxFont.cc */
+ static const char *base_14_subst_fonts[14] = {
+ "Courier",
+ "Courier-Oblique",
+ "Courier-Bold",
+ "Courier-BoldOblique",
+ "Helvetica",
+ "Helvetica-Oblique",
+ "Helvetica-Bold",
+ "Helvetica-BoldOblique",
+ "Times-Roman",
+ "Times-Italic",
+ "Times-Bold",
+ "Times-BoldItalic",
+ "Symbol",
+ "ZapfDingbats"
+ };
+ unsigned int i;
+
+ /* The Standard 14 fonts are all Type 1 fonts. A non embedded TrueType
+ * font with the same name is not a Standard 14 font. */
+ if (type != POPPLER_FONT_TYPE_TYPE1)
+ return FALSE;
+
+ for (i = 0; i < G_N_ELEMENTS (base_14_subst_fonts); i++) {
+ if (g_str_equal (name, base_14_subst_fonts[i]))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static const gchar *
+pdf_document_fonts_get_fonts_summary (EvDocumentFonts *document_fonts)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
+
+ if (pdf_document->missing_fonts)
+ return _("This document contains non-embedded fonts that are not from the "
+ "PDF Standard 14 fonts. If the substitute fonts selected by fontconfig "
+ "are not the same as the fonts used to create the PDF, the rendering may "
+ "not be correct.");
+ else
+ return _("All fonts are either standard or embedded.");
+}
+
static void
pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
GtkTreeModel *model)
@@ -1062,8 +1111,10 @@ pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
do {
GtkTreeIter list_iter;
const char *name;
- const char *type;
+ PopplerFontType type;
+ const char *type_str;
const char *embedded;
+ const char *standard_str = "";
const gchar *substitute;
const gchar *substitute_text;
const gchar *filename;
@@ -1081,8 +1132,8 @@ pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
if (!encoding)
encoding = _("None");
- type = font_type_to_string (
- poppler_fonts_iter_get_font_type (iter));
+ type = poppler_fonts_iter_get_font_type (iter);
+ type_str = font_type_to_string (type);
if (poppler_fonts_iter_is_embedded (iter)) {
if (poppler_fonts_iter_is_subset (iter))
@@ -1091,19 +1142,38 @@ pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
embedded = _("Embedded");
} else {
embedded = _("Not embedded");
+ if (is_standard_font (name, type)) {
+ /* Translators: string starting with a space
+ * because it is directly appended to the font
+ * type. Example:
+ * "Type 1 (One of the Standard 14 Fonts)"
+ */
+ standard_str = _(" (One of the Standard 14 Fonts)");
+ } else {
+ /* Translators: string starting with a space
+ * because it is directly appended to the font
+ * type. Example:
+ * "TrueType (Not one of the Standard 14 Fonts)"
+ */
+ standard_str = _(" (Not one of the Standard 14 Fonts)");
+ pdf_document->missing_fonts = TRUE;
+ }
}
substitute = poppler_fonts_iter_get_substitute_name (iter);
filename = poppler_fonts_iter_get_file_name (iter);
encoding_text = _("Encoding");
- substitute_text = _("substituting with");
+ substitute_text = _("Substituting with");
if (substitute && filename)
- details = g_markup_printf_escaped ("%s\n%s: %s\n%s, %s <b>%s</b>\n(%s)",
- type, encoding_text, encoding, embedded,
+ details = g_markup_printf_escaped ("%s%s\n%s: %s\n%s\n%s <b>%s</b>\n(%s)",
+ type_str, standard_str,
+ encoding_text, encoding, embedded,
substitute_text, substitute, filename);
else
- details = g_markup_printf_escaped ("%s\n%s: %s\n%s", type, encoding_text, encoding, embedded);
+ details = g_markup_printf_escaped ("%s%s\n%s: %s\n%s",
+ type_str, standard_str,
+ encoding_text, encoding, embedded);
gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
@@ -1119,6 +1189,7 @@ static void
pdf_document_document_fonts_iface_init (EvDocumentFontsInterface *iface)
{
iface->fill_model = pdf_document_fonts_fill_model;
+ iface->get_fonts_summary = pdf_document_fonts_get_fonts_summary;
iface->scan = pdf_document_fonts_scan;
iface->get_progress = pdf_document_fonts_get_progress;
}
diff --git a/libdocument/ev-document-fonts.c b/libdocument/ev-document-fonts.c
index 7622f72..8587625 100644
--- a/libdocument/ev-document-fonts.c
+++ b/libdocument/ev-document-fonts.c
@@ -57,3 +57,14 @@ ev_document_fonts_fill_model (EvDocumentFonts *document_fonts,
iface->fill_model (document_fonts, model);
}
+
+const gchar *
+ev_document_fonts_get_fonts_summary (EvDocumentFonts *document_fonts)
+{
+ EvDocumentFontsInterface *iface = EV_DOCUMENT_FONTS_GET_IFACE (document_fonts);
+
+ if (!iface->get_fonts_summary)
+ return NULL;
+
+ return iface->get_fonts_summary (document_fonts);
+}
diff --git a/libdocument/ev-document-fonts.h b/libdocument/ev-document-fonts.h
index 8cabe35..4edc92d 100644
--- a/libdocument/ev-document-fonts.h
+++ b/libdocument/ev-document-fonts.h
@@ -58,20 +58,22 @@ struct _EvDocumentFontsInterface
{
GTypeInterface base_iface;
- /* Methods */
- gboolean (* scan) (EvDocumentFonts *document_fonts,
- int n_pages);
- double (* get_progress) (EvDocumentFonts *document_fonts);
- void (* fill_model) (EvDocumentFonts *document_fonts,
- GtkTreeModel *model);
+ /* Methods */
+ gboolean (* scan) (EvDocumentFonts *document_fonts,
+ int n_pages);
+ double (* get_progress) (EvDocumentFonts *document_fonts);
+ void (* fill_model) (EvDocumentFonts *document_fonts,
+ GtkTreeModel *model);
+ const gchar *(* get_fonts_summary) (EvDocumentFonts *document_fonts);
};
-GType ev_document_fonts_get_type (void);
-gboolean ev_document_fonts_scan (EvDocumentFonts *document_fonts,
- int n_pages);
-double ev_document_fonts_get_progress (EvDocumentFonts *document_fonts);
-void ev_document_fonts_fill_model (EvDocumentFonts *document_fonts,
- GtkTreeModel *model);
+GType ev_document_fonts_get_type (void);
+gboolean ev_document_fonts_scan (EvDocumentFonts *document_fonts,
+ int n_pages);
+double ev_document_fonts_get_progress (EvDocumentFonts *document_fonts);
+void ev_document_fonts_fill_model (EvDocumentFonts *document_fonts,
+ GtkTreeModel *model);
+const gchar *ev_document_fonts_get_fonts_summary (EvDocumentFonts *document_fonts);
G_END_DECLS
diff --git a/shell/ev-properties-fonts.c b/shell/ev-properties-fonts.c
index bb2c24f..f4d4438 100644
--- a/shell/ev-properties-fonts.c
+++ b/shell/ev-properties-fonts.c
@@ -35,6 +35,7 @@ struct _EvPropertiesFonts {
GtkWidget *fonts_treeview;
GtkWidget *fonts_progress_label;
+ GtkWidget *fonts_summary;
EvJob *fonts_job;
EvDocument *document;
@@ -112,10 +113,19 @@ ev_properties_fonts_init (EvPropertiesFonts *properties)
gtk_container_set_border_width (GTK_CONTAINER (properties), 12);
gtk_box_set_spacing (GTK_BOX (properties), 6);
+ properties->fonts_summary = gtk_label_new (NULL);
+ g_object_set (G_OBJECT (properties->fonts_summary),
+ "xalign", 0.0,
+ NULL);
+ gtk_label_set_line_wrap (GTK_LABEL (properties->fonts_summary), TRUE);
+ gtk_box_pack_start (GTK_BOX (properties),
+ properties->fonts_summary,
+ FALSE, FALSE, 0);
+
swindow = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
GTK_SHADOW_IN);
-
+
properties->fonts_treeview = gtk_tree_view_new ();
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (properties->fonts_treeview),
FALSE);
@@ -169,9 +179,21 @@ update_progress_label (GtkWidget *label, double progress)
static void
job_fonts_finished_cb (EvJob *job, EvPropertiesFonts *properties)
{
+ EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (properties->document);
+ const gchar *font_summary;
+
g_signal_handlers_disconnect_by_func (job, job_fonts_finished_cb, properties);
g_object_unref (properties->fonts_job);
properties->fonts_job = NULL;
+
+ font_summary = ev_document_fonts_get_fonts_summary (document_fonts);
+ if (font_summary) {
+ gtk_label_set_text (GTK_LABEL (properties->fonts_summary),
+ font_summary);
+ /* show the label only when fonts are scanned, so the label
+ * does not take space while it is loading */
+ gtk_widget_show (properties->fonts_summary);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]