Commit 0f7f2182 authored by Kristian Høgsberg's avatar Kristian Høgsberg
Browse files

2006-02-28 Kristian Høgsberg <krh@redhat.com>

        * glib/poppler-document.cc (info_dict_get_string): Refactor
        _popper_goo_string_to_utf8() out into it's own function.

        * glib/poppler-page.cc (poppler_page_get_property): Use
        _popper_goo_string_to_utf8() here to convert ucs2 page labels.

        * glib/poppler-page.cc (poppler_page_get_selection_region): Add
        braces to fix warning.

        * poppler/PageLabelInfo.cc: If the label prefix string has a ucs2
        marker, append the number part of the label as ucs2 (#5952).
parent 1bf83cdc
2006-02-28 Kristian Høgsberg <krh@redhat.com>
* glib/poppler-document.cc (info_dict_get_string): Refactor
_popper_goo_string_to_utf8() out into it's own function.
* glib/poppler-page.cc (poppler_page_get_property): Use
_popper_goo_string_to_utf8() here to convert ucs2 page labels.
* glib/poppler-page.cc (poppler_page_get_selection_region): Add
braces to fix warning.
* poppler/PageLabelInfo.cc: If the label prefix string has a ucs2
marker, append the number part of the label as ucs2 (#5952).
2006-02-25 Albert Astals Cid <aacid@kde.org> 2006-02-25 Albert Astals Cid <aacid@kde.org>
* poppler/Object.cc: Fix warning * poppler/Object.cc: Fix warning
......
...@@ -315,40 +315,23 @@ poppler_document_get_attachments (PopplerDocument *document) ...@@ -315,40 +315,23 @@ poppler_document_get_attachments (PopplerDocument *document)
return g_list_reverse (retval); return g_list_reverse (retval);
} }
static gboolean char *_poppler_goo_string_to_utf8(GooString *s)
has_unicode_marker (GooString *string)
{ {
return ((string->getChar (0) & 0xff) == 0xfe && char *result;
(string->getChar (1) & 0xff) == 0xff);
}
static void if (s->hasUnicodeMarker()) {
info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value) result = g_convert (s->getCString () + 2,
{ s->getLength () - 2,
Object obj;
GooString *goo_value;
gchar *result;
if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
obj.free ();
return;
}
goo_value = obj.getString ();
if (has_unicode_marker (goo_value)) {
result = g_convert (goo_value->getCString () + 2,
goo_value->getLength () - 2,
"UTF-8", "UTF-16BE", NULL, NULL, NULL); "UTF-8", "UTF-16BE", NULL, NULL, NULL);
} else { } else {
int len; int len;
gunichar *ucs4_temp; gunichar *ucs4_temp;
int i; int i;
len = goo_value->getLength (); len = s->getLength ();
ucs4_temp = g_new (gunichar, len + 1); ucs4_temp = g_new (gunichar, len + 1);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
ucs4_temp[i] = pdfDocEncoding[(unsigned char)goo_value->getChar(i)]; ucs4_temp[i] = pdfDocEncoding[(unsigned char)s->getChar(i)];
} }
ucs4_temp[i] = 0; ucs4_temp[i] = 0;
...@@ -357,6 +340,25 @@ info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value) ...@@ -357,6 +340,25 @@ info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value)
g_free (ucs4_temp); g_free (ucs4_temp);
} }
return result;
}
static void
info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value)
{
Object obj;
GooString *goo_value;
gchar *result;
if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
obj.free ();
return;
}
goo_value = obj.getString ();
result = _poppler_goo_string_to_utf8(goo_value);
obj.free (); obj.free ();
g_value_set_string (value, result); g_value_set_string (value, result);
...@@ -382,7 +384,7 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value) ...@@ -382,7 +384,7 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
goo_value = obj.getString (); goo_value = obj.getString ();
if (has_unicode_marker (goo_value)) { if (goo_value->hasUnicodeMarker()) {
date_string = g_convert (goo_value->getCString () + 2, date_string = g_convert (goo_value->getCString () + 2,
goo_value->getLength () - 2, goo_value->getLength () - 2,
"UTF-8", "UTF-16BE", NULL, NULL, NULL); "UTF-8", "UTF-16BE", NULL, NULL, NULL);
......
...@@ -498,14 +498,18 @@ poppler_page_render_selection (PopplerPage *page, ...@@ -498,14 +498,18 @@ poppler_page_render_selection (PopplerPage *page,
selection->x2, selection->y2); selection->x2, selection->y2);
GfxColor gfx_background_color = { GfxColor gfx_background_color = {
background_color->red, {
background_color->green, background_color->red,
background_color->blue background_color->green,
background_color->blue
}
}; };
GfxColor gfx_glyph_color = { GfxColor gfx_glyph_color = {
glyph_color->red, {
glyph_color->green, glyph_color->red,
glyph_color->blue glyph_color->green,
glyph_color->blue
}
}; };
text_dev = poppler_page_get_text_output_dev (page); text_dev = poppler_page_get_text_output_dev (page);
...@@ -687,7 +691,7 @@ poppler_page_find_text (PopplerPage *page, ...@@ -687,7 +691,7 @@ poppler_page_find_text (PopplerPage *page,
matches = NULL; matches = NULL;
xMin = 0; xMin = 0;
yMin = 0; yMin = 0;
#warning you probably want to add caseSensitive and backwards as parameters
while (output_dev->findText (ucs4, ucs4_len, while (output_dev->findText (ucs4, ucs4_len,
gFalse, gTrue, // startAtTop, stopAtBottom gFalse, gTrue, // startAtTop, stopAtBottom
gTrue, gFalse, // startAtLast, stopAtLast gTrue, gFalse, // startAtLast, stopAtLast
...@@ -745,12 +749,15 @@ poppler_page_get_property (GObject *object, ...@@ -745,12 +749,15 @@ poppler_page_get_property (GObject *object,
{ {
PopplerPage *page = POPPLER_PAGE (object); PopplerPage *page = POPPLER_PAGE (object);
GooString label; GooString label;
char *utf8_label;
switch (prop_id) switch (prop_id)
{ {
case PROP_LABEL: case PROP_LABEL:
page->document->doc->getCatalog ()->indexToLabel (page->index, &label); page->document->doc->getCatalog ()->indexToLabel (page->index, &label);
g_value_set_string (value, label.getCString()); utf8_label = _poppler_goo_string_to_utf8(&label);
g_value_set_string (value, utf8_label);
g_free (utf8_label);
break; break;
} }
} }
......
...@@ -67,4 +67,7 @@ PopplerAction *_poppler_action_new (PopplerDocument *document, ...@@ -67,4 +67,7 @@ PopplerAction *_poppler_action_new (PopplerDocument *document,
PopplerAttachment *_poppler_attachment_new (PopplerDocument *document, PopplerAttachment *_poppler_attachment_new (PopplerDocument *document,
EmbFile *file); EmbFile *file);
char *_poppler_goo_string_to_utf8(GooString *s);
#endif #endif
...@@ -17,153 +17,3 @@ poppler-enums ...@@ -17,153 +17,3 @@ poppler-enums
<!-- ##### SECTION Stability_Level ##### --> <!-- ##### SECTION Stability_Level ##### -->
<!-- ##### MACRO POPPLER_TYPE_ACTION_TYPE ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_action_type_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_DEST_TYPE ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_dest_type_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_PAGE_LAYOUT ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_page_layout_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_PAGE_MODE ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_page_mode_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_FONT_TYPE ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_font_type_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_VIEWER_PREFERENCES ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_viewer_preferences_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_PERMISSIONS ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_permissions_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_ERROR ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_error_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_ORIENTATION ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_orientation_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_BACKEND ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_backend_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### MACRO POPPLER_TYPE_ACTION_TYPE ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_BACKEND ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_DEST_TYPE ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_ERROR ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_FONT_TYPE ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_ORIENTATION ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_PAGE_LAYOUT ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_PAGE_MODE ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_PERMISSIONS ##### -->
<para>
</para>
<!-- ##### MACRO POPPLER_TYPE_VIEWER_PREFERENCES ##### -->
<para>
</para>
<!-- ##### FUNCTION poppler_action_type_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_backend_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_dest_type_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_error_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_font_type_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_orientation_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_page_layout_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_page_mode_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_permissions_get_type ##### -->
<para>
</para>
@Returns:
<!-- ##### FUNCTION poppler_viewer_preferences_get_type ##### -->
<para>
</para>
@Returns:
...@@ -218,7 +218,7 @@ int main (int argc, char *argv[]) ...@@ -218,7 +218,7 @@ int main (int argc, char *argv[])
poppler_attachment_save (attachment, name, NULL); poppler_attachment_save (attachment, name, NULL);
i++; i++;
} }
g_list_foreach (list, g_object_unref, NULL); g_list_foreach (list, (GFunc) g_object_unref, NULL);
g_list_free (list); g_list_free (list);
} }
else else
......
...@@ -317,3 +317,8 @@ int GooString::cmpN(const char *sA, int n) { ...@@ -317,3 +317,8 @@ int GooString::cmpN(const char *sA, int n) {
} }
return 0; return 0;
} }
GBool GooString::hasUnicodeMarker(void)
{
return (s[0] & 0xff) == 0xfe && (s[1] & 0xff) == 0xff;
}
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#pragma interface #pragma interface
#endif #endif
#include "gtypes.h"
class GooString { class GooString {
public: public:
...@@ -84,6 +86,8 @@ public: ...@@ -84,6 +86,8 @@ public:
int cmp(const char *sA); int cmp(const char *sA);
int cmpN(const char *sA, int n); int cmpN(const char *sA, int n);
GBool hasUnicodeMarker(void);
private: private:
int length; int length;
......
...@@ -158,9 +158,9 @@ PageLabelInfo::Interval::Interval(Object *dict, int baseA) { ...@@ -158,9 +158,9 @@ PageLabelInfo::Interval::Interval(Object *dict, int baseA) {
obj.free(); obj.free();
if (dict->dictLookup("P", &obj)->isString()) if (dict->dictLookup("P", &obj)->isString())
prefix = copyString(obj.getString()->getCString()); prefix = obj.getString()->copy();
else else
prefix = copyString(""); prefix = new GooString("");
obj.free(); obj.free();
if (dict->dictLookup("St", &obj)->isInt()) if (dict->dictLookup("St", &obj)->isInt())
...@@ -173,7 +173,7 @@ PageLabelInfo::Interval::Interval(Object *dict, int baseA) { ...@@ -173,7 +173,7 @@ PageLabelInfo::Interval::Interval(Object *dict, int baseA) {
} }
PageLabelInfo::Interval::~Interval() { PageLabelInfo::Interval::~Interval() {
gfree(prefix); delete prefix;
} }
PageLabelInfo::PageLabelInfo(Object *tree, int numPages) { PageLabelInfo::PageLabelInfo(Object *tree, int numPages) {
...@@ -248,8 +248,8 @@ GBool PageLabelInfo::labelToIndex(GooString *label, int *index) ...@@ -248,8 +248,8 @@ GBool PageLabelInfo::labelToIndex(GooString *label, int *index)
base = 0; base = 0;
for (i = 0; i < intervals.getLength(); i++) { for (i = 0; i < intervals.getLength(); i++) {
interval = (Interval *) intervals.get(i); interval = (Interval *) intervals.get(i);
prefixLength = strlen(interval->prefix); prefixLength = interval->prefix->getLength();
if (strncmp(str, interval->prefix, prefixLength) != 0) if (label->cmpN(interval->prefix, prefixLength) != 0)
continue; continue;
switch (interval->style) { switch (interval->style) {
...@@ -291,9 +291,9 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label) ...@@ -291,9 +291,9 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label)
char buffer[32]; char buffer[32];
int i, base, number; int i, base, number;
Interval *interval; Interval *interval;
GooString number_string;
base = 0; base = 0;
label->clear();
interval = NULL; interval = NULL;
for (i = 0; i < intervals.getLength(); i++) { for (i = 0; i < intervals.getLength(); i++) {
interval = (Interval *) intervals.get(i); interval = (Interval *) intervals.get(i);
...@@ -305,19 +305,17 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label) ...@@ -305,19 +305,17 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label)
if (i == intervals.getLength()) if (i == intervals.getLength())
return gFalse; return gFalse;
label->append(interval->prefix);
number = index - base + interval->first; number = index - base + interval->first;
switch (interval->style) { switch (interval->style) {
case Interval::Arabic: case Interval::Arabic:
snprintf (buffer, sizeof(buffer), "%d", number); snprintf (buffer, sizeof(buffer), "%d", number);
label->append(buffer); number_string.append(buffer);
break; break;
case Interval::LowercaseRoman: case Interval::LowercaseRoman:
toRoman(number, label, gFalse); toRoman(number, &number_string, gFalse);
break;