summaryrefslogtreecommitdiffstatsci
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/img_surf.c19
-rw-r--r--tests/paint_surf.c11
-rw-r--r--tests/text.c71
3 files changed, 73 insertions, 28 deletions
diff --git a/tests/img_surf.c b/tests/img_surf.c
index 11557c0..af6f9a6 100644
--- a/tests/img_surf.c
+++ b/tests/img_surf.c
@@ -1,8 +1,9 @@
#include "test.h"
+
+const char* imgPath = "data/miroir.jpg";
void paint () {
VkvgContext ctx = vkvg_create(surf);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
- //vkvg_surface_write_to_png(imgSurf, "/tmp/test.png");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
vkvg_set_source_surface(ctx, imgSurf, 0, 0);
vkvg_paint(ctx);
@@ -12,7 +13,7 @@ void paint () {
}
void paint_offset () {
VkvgContext ctx = vkvg_create(surf);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
vkvg_set_source_surface(ctx, imgSurf, 100, 100);
vkvg_paint(ctx);
@@ -23,7 +24,7 @@ void paint_offset () {
void paint_with_scale(){
VkvgContext ctx = vkvg_create(surf);
vkvg_scale (ctx, 0.2f,0.2f);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
vkvg_set_source_surface(ctx, imgSurf, 0, 0);
vkvg_paint(ctx);
@@ -34,7 +35,7 @@ void paint_with_scale(){
void paint_pattern () {
VkvgContext ctx = vkvg_create(surf);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf);
vkvg_set_source(ctx, pat);
vkvg_paint(ctx);
@@ -44,7 +45,7 @@ void paint_pattern () {
}
void paint_patt_repeat () {
VkvgContext ctx = vkvg_create(surf);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf);
vkvg_pattern_set_extend(pat,VKVG_EXTEND_REPEAT);
vkvg_set_source(ctx, pat);
@@ -56,7 +57,7 @@ void paint_patt_repeat () {
void paint_patt_repeat_scalled () {
VkvgContext ctx = vkvg_create(surf);
vkvg_scale (ctx, 0.2f,0.2f);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf);
vkvg_pattern_set_extend(pat,VKVG_EXTEND_REPEAT);
vkvg_set_source(ctx, pat);
@@ -67,7 +68,7 @@ void paint_patt_repeat_scalled () {
}
void paint_patt_pad () {
VkvgContext ctx = vkvg_create(surf);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf);
vkvg_pattern_set_extend(pat,VKVG_EXTEND_PAD);
vkvg_set_source(ctx, pat);
@@ -80,7 +81,7 @@ void paint_patt_pad () {
void test(){
VkvgContext ctx = vkvg_create(surf);
vkvg_set_fill_rule(ctx,VKVG_FILL_RULE_EVEN_ODD);
- VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "data/miroir.jpg");
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath);
vkvg_translate(ctx,200,200);
//vkvg_rotate(ctx,M_PI_4);
diff --git a/tests/paint_surf.c b/tests/paint_surf.c
index c945305..0347df9 100644
--- a/tests/paint_surf.c
+++ b/tests/paint_surf.c
@@ -1,7 +1,7 @@
#include "test.h"
vkvg_fill_rule_t fillrule = VKVG_FILL_RULE_NON_ZERO;
-float lineWidth = 20.f;
+float lineWidth = 10.f;
VkvgSurface createSurf (uint32_t width, uint32_t height) {
VkvgSurface s = vkvg_surface_create(device, width, height);
@@ -9,10 +9,13 @@ VkvgSurface createSurf (uint32_t width, uint32_t height) {
vkvg_set_fill_rule(ctx,fillrule);
vkvg_set_line_width(ctx,lineWidth);
float hlw = lineWidth/2.f;
- vkvg_rectangle(ctx,hlw,hlw,(float)width-hlw,(float)height-hlw);
+ /*
vkvg_set_source_rgba(ctx,0,1,0,0.5);
- vkvg_fill_preserve(ctx);
+ vkvg_fill_preserve(ctx);*/
+ vkvg_set_source_rgba(ctx,1,0,0,0.5);
+ vkvg_paint(ctx);
vkvg_set_source_rgba(ctx,0,0,1,0.5);
+ vkvg_rectangle(ctx,hlw,hlw,(float)width-lineWidth,(float)height-lineWidth);
vkvg_stroke(ctx);
vkvg_destroy(ctx);
return s;
@@ -30,6 +33,8 @@ void paint(){
void paint_with_offset(){
VkvgSurface src = createSurf(256,256);
VkvgContext ctx = vkvg_create(surf);
+ vkvg_set_source_rgba(ctx,0,1,0,0.5);
+ vkvg_paint(ctx);
vkvg_set_fill_rule(ctx,fillrule);
vkvg_set_source_surface(ctx, src, 100, 100);
vkvg_paint(ctx);
diff --git a/tests/text.c b/tests/text.c
index fa21ad8..293e63a 100644
--- a/tests/text.c
+++ b/tests/text.c
@@ -4,7 +4,7 @@ static const char* txt = "The quick brown fox jumps over the lazy dog";
void print(VkvgContext ctx, float penY, uint32_t size) {
vkvg_set_font_size(ctx,size);
- vkvg_move_to(ctx, 10,penY);
+ vkvg_move_to(ctx, 10, penY);
vkvg_show_text (ctx,txt);
}
@@ -23,7 +23,7 @@ void test2() {
float penY = 10.f;
- for (uint32_t size=4;size<39;size++) {
+ for (uint32_t size = 4; size < 39; size++) {
print(ctx,(float)penY,size);
penY+=size;
}
@@ -82,19 +82,19 @@ void test(){
//vkvg_select_font_face(ctx, "/usr/local/share/fonts/DroidSansMono.ttf");
//vkvg_select_font_face(ctx, "/usr/share/fonts/truetype/unifont/unifont.ttf");
- vkvg_set_font_size(ctx,12);
- vkvg_select_font_face(ctx, "droid");
+ vkvg_set_font_size (ctx, 12);
+ vkvg_select_font_face (ctx, "droid");
vkvg_font_extents_t fe;
- vkvg_font_extents (ctx,&fe);
- vkvg_move_to(ctx, penX,penY);
- vkvg_set_source_rgba(ctx,fg.r,fg.g,fg.b,fg.a);
+ vkvg_font_extents (ctx, &fe);
+ vkvg_move_to (ctx, penX,penY);
+ vkvg_set_source_rgba (ctx, fg.r, fg.g, fg.b, fg.a);
vkvg_text_extents_t te;
- vkvg_text_extents(ctx,"abcdefghijk",&te);
- vkvg_show_text (ctx,"abcdefghijk");
- penX+= te.x_advance;
+ vkvg_text_extents (ctx, "abcdefghijk", &te);
+ vkvg_show_text (ctx, "abcdefghijk");
+ penX += te.x_advance;
vkvg_move_to(ctx, penX,penY);
vkvg_show_text (ctx,"*abcdefghijk2");
- penY+=2.f*size;
+ penY += 2.f*size;
vkvg_select_font_face(ctx, "times");
vkvg_move_to(ctx, penX,penY);
@@ -152,15 +152,30 @@ void test(){
vkvg_destroy(ctx);
}
-void random_text () {
+void single_font_and_size () {
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_clear(ctx);
+ for (uint32_t i=0; i<test_size; i++) {
+ randomize_color(ctx);
+ float x = rndf() * test_width;
+ float y = rndf() * test_height;
+ vkvg_select_font_face(ctx,"mono");
+ vkvg_set_font_size(ctx, 20);
+ vkvg_move_to(ctx,x,y);
+ vkvg_show_text(ctx,"This is a test string!");
+ }
+ vkvg_destroy(ctx);
+}
+
+void random_size () {
VkvgContext ctx = vkvg_create(surf);
vkvg_clear(ctx);
vkvg_select_font_face(ctx,"mono");
for (uint32_t i=0; i<test_size; i++) {
randomize_color(ctx);
- float x = (float)rand()/RAND_MAX * test_width;
- float y = (float)rand()/RAND_MAX * test_height;
- uint32_t c = (uint32_t)((float)rand()/RAND_MAX * 80)+1;
+ float x = rndf() * test_width;
+ float y = rndf() * test_height;
+ uint32_t c = (uint32_t)(rndf() * 120)+1;
vkvg_set_font_size(ctx, c);
vkvg_move_to(ctx,x,y);
@@ -168,10 +183,34 @@ void random_text () {
}
vkvg_destroy(ctx);
}
+const char* const fonts[] =
+ { "mono", "droid", "times", "arial", "times:bold"};
+
+void random_font_and_size () {
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_clear(ctx);
+
+ for (uint32_t i=0; i<test_size; i++) {
+ randomize_color(ctx);
+ float x = rndf() * test_width;
+ float y = rndf() * test_height;
+ uint32_t c = (uint32_t)(rndf() * 80)+1;
+ uint32_t f = (uint32_t)(rndf() * 4);
+
+ vkvg_set_font_size(ctx, c);
+ vkvg_select_font_face(ctx, fonts[f]);
+ vkvg_move_to(ctx,x,y);
+ vkvg_show_text(ctx,"This is a test string!");
+ }
+ vkvg_destroy(ctx);
+}
+
int main(int argc, char *argv[]) {
no_test_size = true;
//vkvg_log_level = VKVG_LOG_INFO;
- PERFORM_TEST (random_text, argc, argv);
+ PERFORM_TEST (single_font_and_size, argc, argv);
+ PERFORM_TEST (random_size, argc, argv);
+ PERFORM_TEST (random_font_and_size, argc, argv);
PERFORM_TEST (test, argc, argv);
PERFORM_TEST (test1, argc, argv);
PERFORM_TEST (test2, argc, argv);