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
4857d62f
Commit
4857d62f
authored
Nov 18, 2010
by
Moritz Lipp
Browse files
Init document, some changes
parent
f1438f5f
Changes
7
Hide whitespace changes
Inline
Side-by-side
ft/document.c
View file @
4857d62f
...
...
@@ -4,10 +4,63 @@
#include <stdio.h>
#include "document.h"
#include "../utils.h"
#include "pdf/pdf.h"
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
zathura_document_plugin_t
zathura_document_plugins
[]
=
{
{
"pdf"
,
pdf_document_open
},
};
zathura_document_t
*
zathura_document_
create
(
const
char
*
path
)
zathura_document_
open
(
const
char
*
path
,
const
char
*
password
)
{
if
(
!
path
)
{
return
NULL
;
}
if
(
!
file_exists
(
path
))
{
fprintf
(
stderr
,
"error: file does not exist
\n
"
);
return
NULL
;
}
const
char
*
file_extension
=
file_get_extension
(
path
);
if
(
!
file_extension
)
{
fprintf
(
stderr
,
"error: could not determine file type
\n
"
);
return
NULL
;
}
zathura_document_t
*
document
=
malloc
(
sizeof
(
zathura_document_t
));
if
(
!
document
)
{
return
NULL
;
}
document
->
file_path
=
path
;
document
->
password
=
password
;
document
->
current_page_number
=
0
;
document
->
number_of_pages
=
0
;
document
->
scale
=
100
;
document
->
rotate
=
0
;
document
->
functions
.
document_free
=
NULL
;
document
->
functions
.
document_index_generate
=
NULL
;
document
->
functions
.
document_save_as
=
NULL
;
document
->
functions
.
document_attachments_get
=
NULL
;
document
->
functions
.
page_get
=
NULL
;
document
->
functions
.
page_free
=
NULL
;
document
->
functions
.
page_search_text
=
NULL
;
document
->
functions
.
page_links_get
=
NULL
;
document
->
functions
.
page_form_fields_get
=
NULL
;
document
->
functions
.
page_render
=
NULL
;
/* init plugin with associated file type */
for
(
unsigned
int
i
=
0
;
i
<
LENGTH
(
zathura_document_plugins
);
i
++
)
{
}
return
NULL
;
}
...
...
@@ -23,7 +76,11 @@ zathura_document_free(zathura_document_t* document)
return
NULL
;
}
return
document
->
functions
.
document_free
(
document
);
bool
r
=
document
->
functions
.
document_free
(
document
);
free
(
document
);
return
r
;
}
bool
...
...
@@ -86,7 +143,7 @@ zathura_document_attachments_free(zathura_list_t* list)
zathura_page_t
*
zathura_page_get
(
zathura_document_t
*
document
,
unsigned
int
page
)
{
if
(
!
document
)
{
if
(
!
document
||
!
page
)
{
return
NULL
;
}
...
...
@@ -98,6 +155,21 @@ zathura_page_get(zathura_document_t* document, unsigned int page)
return
document
->
functions
.
page_get
(
document
,
page
);
}
bool
zathura_page_free
(
zathura_page_t
*
page
)
{
if
(
!
page
||
!
page
->
document
)
{
return
false
;
}
if
(
!
page
->
document
->
functions
.
page_free
)
{
fprintf
(
stderr
,
"error: %s not implemented
\n
"
,
__FUNCTION__
);
return
false
;
}
return
page
->
document
->
functions
.
page_free
(
page
);
}
zathura_list_t
*
zathura_page_search_text
(
zathura_page_t
*
page
,
const
char
*
text
)
{
...
...
ft/document.h
View file @
4857d62f
...
...
@@ -9,6 +9,14 @@
typedef
struct
zathura_list_s
zathura_list_t
;
typedef
struct
zathura_document_s
zathura_document_t
;
typedef
bool
(
*
zathura_document_open_t
)(
zathura_document_t
*
document
);
typedef
struct
zathura_document_plugin_s
{
const
char
*
file_type
;
zathura_document_open_t
open_function
;
}
zathura_document_plugin_t
;
struct
zathura_list_s
{
void
*
data
;
...
...
@@ -62,8 +70,8 @@ typedef struct zathura_page_s
struct
zathura_document_s
{
char
*
file_path
;
char
*
password
;
const
char
*
file_path
;
const
char
*
password
;
unsigned
int
current_page_number
;
unsigned
int
number_of_pages
;
int
scale
;
...
...
@@ -71,20 +79,21 @@ struct zathura_document_s
struct
{
bool
(
*
document_free
)(
zathura_document_t
*
document
);
zathura_list_t
*
(
*
document_index_generate
)(
zathura_document_t
*
document
);
bool
(
*
document_save_as
)(
zathura_document_t
*
document
,
const
char
*
path
);
zathura_list_t
*
(
*
document_attachments_get
)(
zathura_document_t
*
document
);
zathura_page_t
*
(
*
page_get
)(
zathura_document_t
*
document
,
unsigned
int
page
);
zathura_list_t
*
(
*
page_search_text
)(
zathura_page_t
*
page
,
const
char
*
text
);
zathura_list_t
*
(
*
page_links_get
)(
zathura_page_t
*
page
);
zathura_list_t
*
(
*
page_form_fields_get
)(
zathura_page_t
*
page
);
cairo_surface_t
*
(
*
page_render
)(
zathura_page_t
*
page
);
zathura_list_t
*
(
*
document_index_generate
)(
zathura_document_t
*
document
);
bool
(
*
document_save_as
)(
zathura_document_t
*
document
,
const
char
*
path
);
zathura_list_t
*
(
*
document_attachments_get
)(
zathura_document_t
*
document
);
bool
(
*
document_free
)(
zathura_document_t
*
document
);
bool
(
*
page_free
)(
zathura_page_t
*
page
);
}
functions
;
};
zathura_document_t
*
zathura_document_
create
(
const
char
*
path
);
zathura_document_t
*
zathura_document_
open
(
const
char
*
path
,
const
char
*
password
);
bool
zathura_document_free
(
zathura_document_t
*
document
);
bool
zathura_document_save_as
(
zathura_document_t
*
document
,
const
char
*
path
);
zathura_list_t
*
zathura_document_index_generate
(
zathura_document_t
*
document
);
...
...
@@ -93,6 +102,7 @@ zathura_list_t* zathura_document_attachments_get(zathura_document_t* document);
bool
zathura_document_attachments_free
(
zathura_list_t
*
list
);
zathura_page_t
*
zathura_page_get
(
zathura_document_t
*
document
,
unsigned
int
page
);
bool
zathura_page_free
(
zathura_page_t
*
page
);
zathura_list_t
*
zathura_page_search_text
(
zathura_page_t
*
page
,
const
char
*
text
);
zathura_list_t
*
zathura_page_links_get
(
zathura_page_t
*
page
);
bool
zathura_page_links_free
(
zathura_list_t
*
list
);
...
...
ft/pdf/pdf.c
View file @
4857d62f
/* See LICENSE file for license and copyright information */
#include "pdf.h"
bool
pdf_document_open
(
zathura_document_t
*
document
)
{
return
true
;
}
ft/pdf/pdf.h
View file @
4857d62f
/* See LICENSE file for license and copyright information */
#include <stdbool.h>
#include "../document.h"
bool
pdf_document_open
(
zathura_document_t
*
document
);
utils.c
View file @
4857d62f
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#include <unistd.h>
#include "utils.h"
bool
file_exists
(
const
char
*
path
)
{
if
(
!
access
(
path
,
F_OK
))
{
return
true
;
}
else
{
return
false
;
}
}
const
char
*
file_get_extension
(
const
char
*
path
)
{
return
NULL
;
}
utils.h
View file @
4857d62f
...
...
@@ -3,4 +3,9 @@
#ifndef UTILS_H
#define UTILS_H
#include <stdbool.h>
bool
file_exists
(
const
char
*
path
);
const
char
*
file_get_extension
(
const
char
*
path
);
#endif // UTILS_H
zathura.c
View file @
4857d62f
...
...
@@ -2,6 +2,7 @@
#include "callbacks.h"
#include "config.h"
#include "ft/document.h"
#include "shortcuts.h"
#include "zathura.h"
...
...
@@ -43,14 +44,22 @@ int main(int argc, char* argv[])
gdk_threads_init
();
gtk_init
(
&
argc
,
&
argv
);
if
(
!
init_zathura
())
{
printf
(
"error: coult not initialize zathura
\n
"
);
return
-
1
;
/*if(!init_zathura()) {*/
/*printf("error: coult not initialize zathura\n");*/
/*return -1;*/
/*}*/
if
(
argc
>
1
)
{
zathura_document_t
*
document
=
zathura_document_open
(
argv
[
1
],
NULL
);
if
(
!
document
)
{
return
-
1
;
}
zathura_document_free
(
document
);
}
gdk_threads_enter
();
gtk_main
();
gdk_threads_leave
();
/*
gdk_threads_enter();
*/
/*
gtk_main();
*/
/*
gdk_threads_leave();
*/
return
0
;
}
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