-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
module fig_cairo_poly | ||
use cairo | ||
use fig_shapes | ||
use fig_canvas | ||
use fig_cairo_utils | ||
use fig_poly | ||
|
||
contains | ||
|
||
subroutine write_polyline(canva, cr, pl) | ||
class(base_canvas), intent(inout) :: canva | ||
type(c_ptr), intent(inout):: cr | ||
type(polyline), intent(in) :: pl | ||
type(point), allocatable:: points(:) | ||
integer :: p_count,i | ||
type(canvas_point) :: p | ||
type(canvas_size):: s | ||
call parse_string(pl%poly_string, points, p_count) | ||
|
||
p = to_canvas(points(1), canva%size) | ||
call cairo_move_to(cr, p%x, p%y) | ||
do i = 2, p_count, 1 | ||
p = to_canvas(points(i), canva%size) | ||
call cairo_line_to(cr, p%x, p%y) | ||
end do | ||
|
||
call fill(cr,pl) | ||
call stroke(cr,pl) | ||
end subroutine write_polyline | ||
|
||
subroutine parse_string(input_str, points, p_count) | ||
implicit none | ||
character(len=*), intent(in) :: input_str | ||
type(point), allocatable, intent(out) :: points(:) | ||
integer, intent(out) :: p_count | ||
integer :: i, length | ||
character(len=1) :: current_char | ||
character(len=20) :: temp_string | ||
logical :: is_num | ||
|
||
p_count = -1 | ||
length = len_trim(input_str) | ||
|
||
allocate(points(length)) | ||
|
||
i = 1 | ||
do while (i <= length) | ||
current_char = input_str(i:i) | ||
|
||
if (current_char == '-') then | ||
temp_string = '-' | ||
i = i + 1 | ||
if (i <= length) current_char = input_str(i:i) | ||
is_num = .true. | ||
do while (is_num .and. i <= length) | ||
if ((current_char >= '0' .and. current_char <= '9') .or. current_char == '.') then | ||
temp_string = trim(temp_string) // current_char | ||
i = i + 1 | ||
if (i <= length) then | ||
current_char = input_str(i:i) | ||
else | ||
is_num = .false. | ||
end if | ||
else | ||
is_num = .false. | ||
end if | ||
end do | ||
if (len_trim(temp_string) > 0 .and. temp_string /= '-') then | ||
p_count = p_count + 1 | ||
|
||
if (iand(p_count,1)/=1) then | ||
read(temp_string, *) points(p_count/2+1)%x | ||
else | ||
read(temp_string, *) points(p_count/2+1)%y | ||
end if | ||
end if | ||
else if ((current_char >= '0' .and. current_char <= '9') .or. current_char == '.') then | ||
temp_string = '' | ||
is_num = .true. | ||
do while (is_num .and. i <= length) | ||
if ((current_char >= '0' .and. current_char <= '9') .or. current_char == '.') then | ||
temp_string = trim(temp_string) // current_char | ||
i = i + 1 | ||
if (i <= length) then | ||
current_char = input_str(i:i) | ||
else | ||
is_num = .false. | ||
end if | ||
else | ||
is_num = .false. | ||
end if | ||
end do | ||
if (len_trim(temp_string) > 0) then | ||
p_count = p_count + 1 | ||
|
||
if (iand(p_count,1)/=1) then | ||
read(temp_string, *) points(p_count/2+1)%x | ||
else | ||
read(temp_string, *) points(p_count/2+1)%y | ||
end if | ||
end if | ||
else | ||
i = i + 1 | ||
end if | ||
end do | ||
p_count = (p_count+1) /2 | ||
|
||
end subroutine parse_string | ||
end module fig_cairo_poly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
program path_test | ||
use fig_poly | ||
use fig_drawing | ||
use fig_svg | ||
use fig_types | ||
use fig_bitmap | ||
use fig_test | ||
use fig_rgb_color_constants | ||
use fig_cairo_poly | ||
|
||
implicit none | ||
integer, parameter :: CANVAS_WIDTH = 500 | ||
integer, parameter :: CANVAS_HEIGHT = 180 | ||
character(len=:), allocatable :: file_name | ||
type(drawing) :: canva | ||
type(svg_canvas) :: svg_canva | ||
type(bitmap_canvas) :: bitmap_canva | ||
type(polyline) :: pl | ||
real :: x_points(7) = [0.0, 40.0, 40.0, 80.0, 80.0, 120.0, 120.0] | ||
real :: y_points(7) = [40.0, 40.0, 80.0, 80.0, 120.0, 120.0, 160.0] | ||
integer :: n=7,i | ||
type(point), allocatable:: points(:) | ||
integer :: p_count, real_ind | ||
|
||
x_points=x_points/CANVAS_WIDTH | ||
y_points=y_points/CANVAS_HEIGHT | ||
call canva%init() | ||
file_name= "poly_example" | ||
call pl%add_points(x_points, y_points, n) | ||
pl%stroke_color=FIG_COLOR_RED | ||
pl%fill_color=FIG_COLOR_YELLOW | ||
pl%stroke_width=4 | ||
call canva%add_shape(pl) | ||
|
||
call bitmap_canva%init(CANVAS_WIDTH,CANVAS_HEIGHT,file_name) | ||
call bitmap_canva%apply_shapes(canva) | ||
call bitmap_canva%save_to_png() | ||
call bitmap_canva%save_to_ppm() | ||
call bitmap_canva%destroy() | ||
|
||
call svg_canva%init(CANVAS_WIDTH,CANVAS_HEIGHT,file_name) | ||
call svg_canva%apply_shapes(canva) | ||
call svg_canva%save_to_svg() | ||
call svg_canva%destroy() | ||
call test_both(file_name,bitmap_canva) | ||
|
||
end program path_test | ||
|