Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
7c6b0819
Commit
7c6b0819
authored
Dec 23, 2010
by
Moritz Lipp
Browse files
Revised pdf/djvu open functions
parent
876f1e9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
ft/djvu/djvu.c
View file @
7c6b0819
...
...
@@ -8,7 +8,7 @@ bool
djvu_document_open
(
zathura_document_t
*
document
)
{
if
(
!
document
)
{
return
false
;
goto
error_out
;
}
document
->
functions
.
document_free
=
djvu_document_free
;
...
...
@@ -24,30 +24,57 @@ djvu_document_open(zathura_document_t* document)
document
->
data
=
malloc
(
sizeof
(
djvu_document_t
));
if
(
!
document
->
data
)
{
return
false
;
goto
error_out
;
}
djvu_document_t
*
djvu_document
=
(
djvu_document_t
*
)
document
->
data
;
djvu_document
->
context
=
ddjvu_context_create
(
"zathura"
);
djvu_document
->
context
=
NULL
;
djvu_document
->
document
=
NULL
;
djvu_document
->
format
=
NULL
;
/* setup format */
djvu_document
->
format
=
ddjvu_format_create
(
DDJVU_FORMAT_RGBMASK32
,
0
,
NULL
);
if
(
!
djvu_document
->
format
)
{
goto
error_free
;
}
ddjvu_format_set_row_order
(
djvu_document
->
format
,
TRUE
);
/* setup context */
djvu_document
->
context
=
ddjvu_context_create
(
"zathura"
);
if
(
!
djvu_document
->
context
)
{
free
(
document
->
data
);
document
->
data
=
NULL
;
return
false
;
goto
error_free
;
}
/* setup document */
djvu_document
->
document
=
ddjvu_document_create_by_filename
(
djvu_document
->
context
,
document
->
file_path
,
FALSE
);
if
(
!
djvu_document
->
document
)
{
ddjvu_context_release
(
djvu_document
->
context
);
free
(
document
->
data
);
document
->
data
=
NULL
;
return
false
;
goto
error_free
;
}
document
->
number_of_pages
=
ddjvu_document_get_pagenum
(
djvu_document
->
document
);
return
true
;
error_free:
if
(
djvu_document
->
format
)
{
ddjvu_format_release
(
djvu_document
->
format
);
}
if
(
djvu_document
->
context
)
{
ddjvu_context_release
(
djvu_document
->
context
);
}
free
(
document
->
data
);
document
->
data
=
NULL
;
error_out:
return
false
;
}
bool
...
...
@@ -61,6 +88,7 @@ djvu_document_free(zathura_document_t* document)
djvu_document_t
*
djvu_document
=
(
djvu_document_t
*
)
document
->
data
;
ddjvu_context_release
(
djvu_document
->
context
);
ddjvu_document_release
(
djvu_document
->
document
);
ddjvu_format_release
(
djvu_document
->
format
);
free
(
document
->
data
);
}
...
...
@@ -80,7 +108,17 @@ djvu_document_save_as(zathura_document_t* document, const char* path)
return
false
;
}
return
false
;
djvu_document_t
*
djvu_document
=
(
djvu_document_t
*
)
document
->
data
;
FILE
*
fp
=
fopen
(
path
,
"w"
);
if
(
!
fp
)
{
return
false
;
}
ddjvu_document_save
(
djvu_document
->
document
,
fp
,
0
,
NULL
);
fclose
(
fp
);
return
true
;
}
zathura_list_t
*
...
...
ft/djvu/djvu.h
View file @
7c6b0819
...
...
@@ -12,6 +12,7 @@ typedef struct djvu_document_s
{
ddjvu_context_t
*
context
;
ddjvu_document_t
*
document
;
ddjvu_format_t
*
format
;
}
djvu_document_t
;
bool
djvu_document_open
(
zathura_document_t
*
document
);
...
...
ft/pdf/pdf.c
View file @
7c6b0819
...
...
@@ -7,8 +7,9 @@
bool
pdf_document_open
(
zathura_document_t
*
document
)
{
if
(
!
document
)
return
false
;
if
(
!
document
)
{
goto
error_out
;
}
document
->
functions
.
document_free
=
pdf_document_free
;
document
->
functions
.
document_index_generate
=
pdf_document_index_generate
;;
...
...
@@ -23,7 +24,7 @@ pdf_document_open(zathura_document_t* document)
document
->
data
=
malloc
(
sizeof
(
pdf_document_t
));
if
(
!
document
->
data
)
{
return
false
;
goto
error_out
;
}
/* format path */
...
...
@@ -32,10 +33,7 @@ pdf_document_open(zathura_document_t* document)
if
(
!
file_uri
)
{
fprintf
(
stderr
,
"error: could not open file: %s
\n
"
,
error
->
message
);
g_error_free
(
error
);
free
(
document
->
data
);
document
->
data
=
NULL
;
return
false
;
goto
error_free
;
}
pdf_document_t
*
pdf_document
=
(
pdf_document_t
*
)
document
->
data
;
...
...
@@ -43,15 +41,29 @@ pdf_document_open(zathura_document_t* document)
if
(
!
pdf_document
->
document
)
{
fprintf
(
stderr
,
"error: could not open file: %s
\n
"
,
error
->
message
);
g_error_free
(
error
);
free
(
document
->
data
);
document
->
data
=
NULL
;
return
false
;
goto
error_free
;
}
document
->
number_of_pages
=
poppler_document_get_n_pages
(
pdf_document
->
document
);
return
true
;
error_free:
if
(
error
)
{
g_error_free
(
error
);
}
if
(
file_uri
)
{
g_free
(
file_uri
);
}
free
(
document
->
data
);
document
->
data
=
NULL
;
error_out:
return
false
;
}
bool
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment