Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
librsvg
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
175
Issues
175
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GNOME
librsvg
Commits
7688fa70
Commit
7688fa70
authored
Oct 10, 2002
by
Dom Lachowicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support --dpi argument in test-display and rsvg
parent
3e6e391a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
98 deletions
+118
-98
ChangeLog
ChangeLog
+6
-0
rsvg.c
rsvg.c
+10
-6
rsvg.h
rsvg.h
+1
-1
test-display.c
test-display.c
+96
-91
test-rsvg.c
test-rsvg.c
+5
-0
No files found.
ChangeLog
View file @
7688fa70
2002
-
10
-
10
Dom
Lachowicz
<
doml
@
appligent
.
com
>
*
rsvg
.
c
(
rsvg_set_default_dpi
):
Rename
function
*
test
-
rsvg
.
c
:
Support
--
dpi
argument
*
test
-
display
.
c
:
Support
--
dpi
argument
2002
-
10
-
09
Dom
Lachowicz
<
doml
@
appligent
.
com
>
*
rsvg
.
c
(
rsvg_start_svg
):
Fix
for
zoom
calculations
...
...
rsvg.c
View file @
7688fa70
...
...
@@ -213,7 +213,7 @@ static void
rsvg_start_svg
(
RsvgHandle
*
ctx
,
const
xmlChar
**
atts
)
{
int
i
;
int
width
=
-
1
,
height
=
-
1
;
int
width
=
-
1
,
height
=
-
1
,
x
=
-
1
,
y
=
-
1
;
int
rowstride
;
art_u8
*
pixels
;
gint
percent
,
em
,
ex
;
...
...
@@ -231,11 +231,15 @@ rsvg_start_svg (RsvgHandle *ctx, const xmlChar **atts)
for
(
i
=
0
;
atts
[
i
]
!=
NULL
;
i
+=
2
)
{
/* x & y should be ignored since we should always be the outermost SVG,
at least for now */
at least for now
, but i'll include them here anyway
*/
if
(
!
strcmp
((
char
*
)
atts
[
i
],
"width"
))
width
=
rsvg_css_parse_length
((
char
*
)
atts
[
i
+
1
],
ctx
->
dpi
,
&
percent
,
&
em
,
&
ex
);
else
if
(
!
strcmp
((
char
*
)
atts
[
i
],
"height"
))
height
=
rsvg_css_parse_length
((
char
*
)
atts
[
i
+
1
],
ctx
->
dpi
,
&
percent
,
&
em
,
&
ex
);
else
if
(
!
strcmp
((
char
*
)
atts
[
i
],
"x"
))
x
=
rsvg_css_parse_length
((
char
*
)
atts
[
i
+
1
],
ctx
->
dpi
,
&
percent
,
&
em
,
&
ex
);
else
if
(
!
strcmp
((
char
*
)
atts
[
i
],
"y"
))
y
=
rsvg_css_parse_length
((
char
*
)
atts
[
i
+
1
],
ctx
->
dpi
,
&
percent
,
&
em
,
&
ex
);
else
if
(
!
strcmp
((
char
*
)
atts
[
i
],
"viewBox"
))
{
/* todo: viewbox can have whitespace and/or comma but we're only likely to see
...
...
@@ -248,8 +252,8 @@ rsvg_start_svg (RsvgHandle *ctx, const xmlChar **atts)
if
(
has_vbox
&&
vbox_w
>
0
.
&&
vbox_h
>
0
.)
{
new_width
=
(
int
)
floor
(
vbox_w
-
vbox_x
);
new_height
=
(
int
)
floor
(
vbox_h
-
vbox_y
);
new_width
=
(
int
)
floor
(
vbox_w
);
new_height
=
(
int
)
floor
(
vbox_h
);
/* apply the sizing function on the *original* width and height
to acquire our real destination size. we'll scale it against
...
...
@@ -2560,7 +2564,7 @@ rsvg_handle_new (void)
}
/**
* rsvg_set_dpi
* rsvg_set_d
efault_d
pi
* @dpi: Dots Per Inch (aka Pixels Per Inch)
*
* Sets the DPI for the all future outgoing pixbufs. Common values are
...
...
@@ -2568,7 +2572,7 @@ rsvg_handle_new (void)
* reset the DPI to whatever the default value happens to be.
*/
void
rsvg_set_dpi
(
double
dpi
)
rsvg_set_d
efault_d
pi
(
double
dpi
)
{
if
(
dpi
<=
0
.)
internal_dpi
=
RSVG_DEFAULT_DPI
;
...
...
rsvg.h
View file @
7688fa70
...
...
@@ -42,7 +42,7 @@ typedef void (* RsvgSizeFunc) (gint *width,
gpointer
user_data
);
void
rsvg_set_d
pi
(
double
dpi
);
void
rsvg_set_d
efault_dpi
(
double
dpi
);
RsvgHandle
*
rsvg_handle_new
(
void
);
void
rsvg_handle_set_dpi
(
RsvgHandle
*
handle
,
double
dpi
);
...
...
test-display.c
View file @
7688fa70
...
...
@@ -30,107 +30,112 @@
static
void
quit_cb
(
GtkWidget
*
win
,
gpointer
unused
)
{
/* exit the main loop */
gtk_main_quit
();
/* exit the main loop */
gtk_main_quit
();
}
static
void
view_pixbuf
(
GdkPixbuf
*
pixbuf
)
{
GtkWidget
*
win
,
*
img
;
/* create toplevel window and set its title */
win
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
gtk_window_set_title
(
GTK_WINDOW
(
win
),
"SVG Viewer"
);
/* exit when 'X' is clicked */
g_signal_connect
(
G_OBJECT
(
win
),
"destroy"
,
G_CALLBACK
(
quit_cb
),
NULL
);
/* create a new image */
img
=
gtk_image_new_from_pixbuf
(
pixbuf
);
/* pack the window with the image */
gtk_container_add
(
GTK_CONTAINER
(
win
),
img
);
gtk_widget_show_all
(
win
);
GtkWidget
*
win
,
*
img
;
/* create toplevel window and set its title */
win
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
gtk_window_set_title
(
GTK_WINDOW
(
win
),
"SVG Viewer"
);
/* exit when 'X' is clicked */
g_signal_connect
(
G_OBJECT
(
win
),
"destroy"
,
G_CALLBACK
(
quit_cb
),
NULL
);
/* create a new image */
img
=
gtk_image_new_from_pixbuf
(
pixbuf
);
/* pack the window with the image */
gtk_container_add
(
GTK_CONTAINER
(
win
),
img
);
gtk_widget_show_all
(
win
);
}
int
main
(
int
argc
,
char
**
argv
)
{
poptContext
popt_context
;
double
x_zoom
=
1
.
0
;
double
y_zoom
=
1
.
0
;
int
width
=
-
1
;
int
height
=
-
1
;
int
bVersion
=
0
;
struct
poptOption
options_table
[]
=
{
{
"x-zoom"
,
'x'
,
POPT_ARG_DOUBLE
,
&
x_zoom
,
0
,
"x zoom factor"
,
"<float>"
},
{
"y-zoom"
,
'y'
,
POPT_ARG_DOUBLE
,
&
y_zoom
,
0
,
"y zoom factor"
,
"<float>"
},
{
"width"
,
'w'
,
POPT_ARG_INT
,
&
width
,
0
,
"width"
,
"<int>"
},
{
"height"
,
'h'
,
POPT_ARG_INT
,
&
height
,
0
,
"height"
,
"<int>"
},
{
"version"
,
'v'
,
POPT_ARG_NONE
,
&
bVersion
,
0
,
"show version information"
,
NULL
},
POPT_AUTOHELP
POPT_TABLEEND
};
int
c
;
const
char
*
const
*
args
;
gint
n_args
=
0
;
GdkPixbuf
*
pixbuf
;
poptContext
popt_context
;
double
x_zoom
=
1
.
0
;
double
y_zoom
=
1
.
0
;
double
dpi
=
-
1
.
0
;
int
width
=
-
1
;
int
height
=
-
1
;
int
bVersion
=
0
;
struct
poptOption
options_table
[]
=
{
{
"dpi"
,
'd'
,
POPT_ARG_DOUBLE
,
&
dpi
,
0
,
"Pixels Per Inch"
,
"<float>"
},
{
"x-zoom"
,
'x'
,
POPT_ARG_DOUBLE
,
&
x_zoom
,
0
,
"x zoom factor"
,
"<float>"
},
{
"y-zoom"
,
'y'
,
POPT_ARG_DOUBLE
,
&
y_zoom
,
0
,
"y zoom factor"
,
"<float>"
},
{
"width"
,
'w'
,
POPT_ARG_INT
,
&
width
,
0
,
"width"
,
"<int>"
},
{
"height"
,
'h'
,
POPT_ARG_INT
,
&
height
,
0
,
"height"
,
"<int>"
},
{
"version"
,
'v'
,
POPT_ARG_NONE
,
&
bVersion
,
0
,
"show version information"
,
NULL
},
POPT_AUTOHELP
POPT_TABLEEND
};
int
c
;
const
char
*
const
*
args
;
gint
n_args
=
0
;
GdkPixbuf
*
pixbuf
;
popt_context
=
poptGetContext
(
"svg-display"
,
argc
,
(
const
char
**
)
argv
,
options_table
,
0
);
poptSetOtherOptionHelp
(
popt_context
,
"[OPTIONS...] file.svg"
);
c
=
poptGetNextOpt
(
popt_context
);
args
=
poptGetArgs
(
popt_context
);
if
(
bVersion
!=
0
)
{
printf
(
"svg-display version %s
\n
"
,
VERSION
);
return
0
;
}
if
(
args
)
{
while
(
args
[
n_args
]
!=
NULL
)
n_args
++
;
}
popt_context
=
poptGetContext
(
"svg-display"
,
argc
,
(
const
char
**
)
argv
,
options_table
,
0
);
poptSetOtherOptionHelp
(
popt_context
,
"[OPTIONS...] file.svg"
);
c
=
poptGetNextOpt
(
popt_context
);
args
=
poptGetArgs
(
popt_context
);
if
(
bVersion
!=
0
)
{
printf
(
"svg-display version %s
\n
"
,
VERSION
);
return
0
;
}
if
(
args
)
{
while
(
args
[
n_args
]
!=
NULL
)
n_args
++
;
}
if
(
n_args
!=
1
)
{
poptPrintHelp
(
popt_context
,
stderr
,
0
);
poptFreeContext
(
popt_context
);
return
1
;
}
/* initialize gtk+ */
gtk_init
(
&
argc
,
&
argv
)
;
/* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */
if
(
width
==
-
1
&&
height
==
-
1
)
pixbuf
=
rsvg_pixbuf_from_file_at_zoom
(
args
[
0
],
x_zoom
,
y_zoom
,
NULL
);
/* if both are unspecified, assume user wants to resize pixbuf in at least 1 dimension */
else
if
(
x_zoom
==
1
.
0
&&
y_zoom
==
1
.
0
)
pixbuf
=
rsvg_pixbuf_from_file_at_size
(
args
[
0
],
width
,
height
,
NULL
);
else
/* assume the user wants to zoom the pixbuf, but cap the maximum size */
pixbuf
=
rsvg_pixbuf_from_file_at_zoom_with_max
(
args
[
0
],
x_zoom
,
y_zoom
,
width
,
height
,
NULL
);
poptFreeContext
(
popt_context
);
if
(
!
pixbuf
)
{
fprintf
(
stderr
,
"Error displaying pixbuf!
\n
"
);
return
1
;
}
view_pixbuf
(
pixbuf
);
/* run the gtk+ main loop */
gtk_main
();
g_object_unref
(
G_OBJECT
(
pixbuf
));
return
0
;
if
(
n_args
!=
1
)
{
poptPrintHelp
(
popt_context
,
stderr
,
0
);
poptFreeContext
(
popt_context
);
return
1
;
}
/* initialize gtk+ */
gtk_init
(
&
argc
,
&
argv
)
;
if
(
dpi
>
0
.)
rsvg_set_default_dpi
(
dpi
);
/* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */
if
(
width
==
-
1
&&
height
==
-
1
)
pixbuf
=
rsvg_pixbuf_from_file_at_zoom
(
args
[
0
],
x_zoom
,
y_zoom
,
NULL
);
/* if both are unspecified, assume user wants to resize pixbuf in at least 1 dimension */
else
if
(
x_zoom
==
1
.
0
&&
y_zoom
==
1
.
0
)
pixbuf
=
rsvg_pixbuf_from_file_at_size
(
args
[
0
],
width
,
height
,
NULL
);
else
/* assume the user wants to zoom the pixbuf, but cap the maximum size */
pixbuf
=
rsvg_pixbuf_from_file_at_zoom_with_max
(
args
[
0
],
x_zoom
,
y_zoom
,
width
,
height
,
NULL
);
poptFreeContext
(
popt_context
);
if
(
!
pixbuf
)
{
fprintf
(
stderr
,
"Error displaying pixbuf!
\n
"
);
return
1
;
}
view_pixbuf
(
pixbuf
);
/* run the gtk+ main loop */
gtk_main
();
g_object_unref
(
G_OBJECT
(
pixbuf
));
return
0
;
}
test-rsvg.c
View file @
7688fa70
...
...
@@ -37,12 +37,14 @@ main (int argc, const char **argv)
poptContext
popt_context
;
double
x_zoom
=
1
.
0
;
double
y_zoom
=
1
.
0
;
double
dpi
=
-
1
.
0
;
int
width
=
-
1
;
int
height
=
-
1
;
int
bVersion
=
0
;
char
*
format
=
"png"
;
struct
poptOption
options_table
[]
=
{
{
"dpi"
,
'd'
,
POPT_ARG_DOUBLE
,
&
dpi
,
0
,
"Pixels Per Inch"
,
"<float>"
},
{
"x-zoom"
,
'x'
,
POPT_ARG_DOUBLE
,
&
x_zoom
,
0
,
"x zoom factor"
,
"<float>"
},
{
"y-zoom"
,
'y'
,
POPT_ARG_DOUBLE
,
&
y_zoom
,
0
,
"y zoom factor"
,
"<float>"
},
{
"width"
,
'w'
,
POPT_ARG_INT
,
&
width
,
0
,
"width"
,
"<int>"
},
...
...
@@ -89,6 +91,9 @@ main (int argc, const char **argv)
g_type_init
();
if
(
dpi
>
0
.)
rsvg_set_default_dpi
(
dpi
);
/* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */
if
(
width
==
-
1
&&
height
==
-
1
)
pixbuf
=
rsvg_pixbuf_from_file_at_zoom
(
args
[
0
],
x_zoom
,
y_zoom
,
NULL
);
...
...
Write
Preview
Markdown
is supported
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