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>
* poppler/Object.cc: Fix warning
......
......@@ -315,40 +315,23 @@ poppler_document_get_attachments (PopplerDocument *document)
return g_list_reverse (retval);
}
static gboolean
has_unicode_marker (GooString *string)
char *_poppler_goo_string_to_utf8(GooString *s)
{
return ((string->getChar (0) & 0xff) == 0xfe &&
(string->getChar (1) & 0xff) == 0xff);
}
char *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 ();
if (has_unicode_marker (goo_value)) {
result = g_convert (goo_value->getCString () + 2,
goo_value->getLength () - 2,
if (s->hasUnicodeMarker()) {
result = g_convert (s->getCString () + 2,
s->getLength () - 2,
"UTF-8", "UTF-16BE", NULL, NULL, NULL);
} else {
int len;
gunichar *ucs4_temp;
int i;
len = goo_value->getLength ();
len = s->getLength ();
ucs4_temp = g_new (gunichar, len + 1);
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;
......@@ -357,6 +340,25 @@ info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value)
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 ();
g_value_set_string (value, result);
......@@ -382,7 +384,7 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
goo_value = obj.getString ();
if (has_unicode_marker (goo_value)) {
if (goo_value->hasUnicodeMarker()) {
date_string = g_convert (goo_value->getCString () + 2,
goo_value->getLength () - 2,
"UTF-8", "UTF-16BE", NULL, NULL, NULL);
......
......@@ -498,14 +498,18 @@ poppler_page_render_selection (PopplerPage *page,
selection->x2, selection->y2);
GfxColor gfx_background_color = {
background_color->red,
background_color->green,
background_color->blue
{
background_color->red,
background_color->green,
background_color->blue
}
};
GfxColor gfx_glyph_color = {
glyph_color->red,
glyph_color->green,
glyph_color->blue
{
glyph_color->red,
glyph_color->green,
glyph_color->blue
}
};
text_dev = poppler_page_get_text_output_dev (page);
......@@ -687,7 +691,7 @@ poppler_page_find_text (PopplerPage *page,
matches = NULL;
xMin = 0;
yMin = 0;
#warning you probably want to add caseSensitive and backwards as parameters
while (output_dev->findText (ucs4, ucs4_len,
gFalse, gTrue, // startAtTop, stopAtBottom
gTrue, gFalse, // startAtLast, stopAtLast
......@@ -745,12 +749,15 @@ poppler_page_get_property (GObject *object,
{
PopplerPage *page = POPPLER_PAGE (object);
GooString label;
char *utf8_label;
switch (prop_id)
{
case PROP_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;
}
}
......
......@@ -67,4 +67,7 @@ PopplerAction *_poppler_action_new (PopplerDocument *document,
PopplerAttachment *_poppler_attachment_new (PopplerDocument *document,
EmbFile *file);
char *_poppler_goo_string_to_utf8(GooString *s);
#endif
......@@ -17,153 +17,3 @@ poppler-enums
<!-- ##### 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[])
poppler_attachment_save (attachment, name, NULL);
i++;
}
g_list_foreach (list, g_object_unref, NULL);
g_list_foreach (list, (GFunc) g_object_unref, NULL);
g_list_free (list);
}
else
......
......@@ -317,3 +317,8 @@ int GooString::cmpN(const char *sA, int n) {
}
return 0;
}
GBool GooString::hasUnicodeMarker(void)
{
return (s[0] & 0xff) == 0xfe && (s[1] & 0xff) == 0xff;
}
......@@ -15,6 +15,8 @@
#pragma interface
#endif
#include "gtypes.h"
class GooString {
public:
......@@ -84,6 +86,8 @@ public:
int cmp(const char *sA);
int cmpN(const char *sA, int n);
GBool hasUnicodeMarker(void);
private:
int length;
......
......@@ -158,9 +158,9 @@ PageLabelInfo::Interval::Interval(Object *dict, int baseA) {
obj.free();
if (dict->dictLookup("P", &obj)->isString())
prefix = copyString(obj.getString()->getCString());
prefix = obj.getString()->copy();
else
prefix = copyString("");
prefix = new GooString("");
obj.free();
if (dict->dictLookup("St", &obj)->isInt())
......@@ -173,7 +173,7 @@ PageLabelInfo::Interval::Interval(Object *dict, int baseA) {
}
PageLabelInfo::Interval::~Interval() {
gfree(prefix);
delete prefix;
}
PageLabelInfo::PageLabelInfo(Object *tree, int numPages) {
......@@ -248,8 +248,8 @@ GBool PageLabelInfo::labelToIndex(GooString *label, int *index)
base = 0;
for (i = 0; i < intervals.getLength(); i++) {
interval = (Interval *) intervals.get(i);
prefixLength = strlen(interval->prefix);
if (strncmp(str, interval->prefix, prefixLength) != 0)
prefixLength = interval->prefix->getLength();
if (label->cmpN(interval->prefix, prefixLength) != 0)
continue;
switch (interval->style) {
......@@ -291,9 +291,9 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label)
char buffer[32];
int i, base, number;
Interval *interval;
GooString number_string;
base = 0;
label->clear();
interval = NULL;
for (i = 0; i < intervals.getLength(); i++) {
interval = (Interval *) intervals.get(i);
......@@ -305,19 +305,17 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label)
if (i == intervals.getLength())
return gFalse;
label->append(interval->prefix);
number = index - base + interval->first;
switch (interval->style) {
case Interval::Arabic:
snprintf (buffer, sizeof(buffer), "%d", number);
label->append(buffer);
number_string.append(buffer);
break;
case Interval::LowercaseRoman:
toRoman(number, label, gFalse);
toRoman(number, &number_string, gFalse);
break;
case Interval::UppercaseRoman:
toRoman(number, label, gTrue);
toRoman(number, &number_string, gTrue);
break;
case Interval::UppercaseLatin:
case Interval::LowercaseLatin:
......@@ -327,6 +325,25 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label)
break;
}
label->clear();
label->append(interval->prefix);
if (label->hasUnicodeMarker()) {
int i, len;
char ucs2_char[2];
/* Convert the ascii number string to ucs2 and append. */
len = number_string.getLength ();
ucs2_char[0] = 0;
for (i = 0; i < len; ++i) {
ucs2_char[1] = number_string.getChar(i);
label->append(ucs2_char, 2);
}
ucs2_char[1] = 0;
label->append(ucs2_char, 2);
} else {
label->append(&number_string);
}
return gTrue;
}
......
......@@ -23,7 +23,7 @@ private:
struct Interval {
Interval(Object *dict, int baseA);
~Interval();
char *prefix;
GooString *prefix;
enum NumberStyle {
None,
Arabic,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment