aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/examples/ttf_font
diff options
context:
space:
mode:
Diffstat (limited to 'v_windows/v/old/examples/ttf_font')
-rw-r--r--v_windows/v/old/examples/ttf_font/Graduate-Regular.ttfbin0 -> 21292 bytes
-rw-r--r--v_windows/v/old/examples/ttf_font/Imprima-Regular.ttfbin0 -> 23188 bytes
-rw-r--r--v_windows/v/old/examples/ttf_font/OFL.txt93
-rw-r--r--v_windows/v/old/examples/ttf_font/example_ttf.v171
4 files changed, 264 insertions, 0 deletions
diff --git a/v_windows/v/old/examples/ttf_font/Graduate-Regular.ttf b/v_windows/v/old/examples/ttf_font/Graduate-Regular.ttf
new file mode 100644
index 0000000..0ce68b7
--- /dev/null
+++ b/v_windows/v/old/examples/ttf_font/Graduate-Regular.ttf
Binary files differ
diff --git a/v_windows/v/old/examples/ttf_font/Imprima-Regular.ttf b/v_windows/v/old/examples/ttf_font/Imprima-Regular.ttf
new file mode 100644
index 0000000..9c701e1
--- /dev/null
+++ b/v_windows/v/old/examples/ttf_font/Imprima-Regular.ttf
Binary files differ
diff --git a/v_windows/v/old/examples/ttf_font/OFL.txt b/v_windows/v/old/examples/ttf_font/OFL.txt
new file mode 100644
index 0000000..3a5f6c1
--- /dev/null
+++ b/v_windows/v/old/examples/ttf_font/OFL.txt
@@ -0,0 +1,93 @@
+Copyright (c) 2012, Eduardo Tunni (http://www.tipo.net.ar), with Reserved Font Name "Imprima"
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/v_windows/v/old/examples/ttf_font/example_ttf.v b/v_windows/v/old/examples/ttf_font/example_ttf.v
new file mode 100644
index 0000000..02e43cd
--- /dev/null
+++ b/v_windows/v/old/examples/ttf_font/example_ttf.v
@@ -0,0 +1,171 @@
+import gg
+import gx
+import sokol.sapp
+import sokol.sgl
+import x.ttf
+import os
+
+// import math
+const (
+ win_width = 600
+ win_height = 700
+ bg_color = gx.white
+ font_paths = [
+ os.resource_abs_path('Imprima-Regular.ttf'),
+ os.resource_abs_path('Graduate-Regular.ttf'),
+ ]
+)
+
+// UI
+struct App_data {
+pub mut:
+ gg &gg.Context
+ sg_img C.sg_image
+ init_flag bool
+ frame_c int
+ tf []ttf.TTF_File
+ ttf_render []ttf.TTF_render_Sokol
+ text_ready_flag bool
+ mouse_x int = -1
+ mouse_y int = -1
+}
+
+fn my_init(mut app App_data) {
+ app.init_flag = true
+}
+
+fn draw_frame(mut app App_data) {
+ cframe_txt := 'Current Frame: $app.frame_c'
+ app.gg.begin()
+ sgl.defaults()
+ sgl.matrix_mode_projection()
+ sgl.ortho(0.0, f32(sapp.width()), f32(sapp.height()), 0.0, -1.0, 1.0)
+ sgl.c4b(0, 0, 0, 255) // black
+ // draw a line as background
+ sgl.begin_line_strip()
+ sgl.v2f(10, 10)
+ sgl.v2f(100, 100)
+ sgl.end()
+ // draw text only if the app is already initialized
+ if app.init_flag == true {
+ sgl.begin_line_strip()
+ sgl.v2f(410, 400)
+ sgl.v2f(510, 400)
+ sgl.end()
+ // update the text
+ mut txt1 := unsafe { &app.ttf_render[0] }
+ if app.frame_c % 2 == 0 {
+ txt1.destroy_texture()
+ txt1.create_text(cframe_txt, 43)
+ txt1.create_texture()
+ }
+ // ----- decomment if you want text rotation ----
+ // txt1.bmp.angle = 3.141592 / 180 * f32(app.frame_c % 360)
+ // txt1.draw_text_bmp(app.gg, 300, 350)
+ // txt1.bmp.angle = 0
+ txt1.draw_text_bmp(app.gg, 30, 60)
+ // block test
+ block_txt := "Today it is a good day!
+Tommorow I'm not so sure :(
+Frame: $app.frame_c
+But Vwill prevail for sure, V is the way!!
+òàèì@ò!£$%&
+"
+ txt1 = unsafe { &app.ttf_render[1] }
+ if app.frame_c % 2 == 0 {
+ txt1.bmp.justify = false
+ if (app.frame_c >> 6) % 2 == 0 {
+ // txt1.align = .left
+ txt1.bmp.justify = true
+ }
+ txt1.bmp.align = .left
+ if (app.frame_c >> 6) % 3 == 0 {
+ txt1.bmp.align = .right
+ }
+ txt1.destroy_texture()
+ txt1.create_text_block(block_txt, 500, 500, 32)
+ txt1.create_texture()
+ }
+ // decomment if want block color change
+ // txt1.bmp.color = ttf.color_multiply(0xFF00FFFF, f32(app.frame_c % 255)/255.0)
+ // decomment if want block rotation wanted
+ // txt1.bmp.angle = 3.141592/180 * f32(app.frame_c % 45)
+ txt1.draw_text_bmp(app.gg, 30 + (app.frame_c >> 1) & 0xFF, 200)
+ // draw mouse position
+ if app.mouse_x >= 0 {
+ txt1 = unsafe { &app.ttf_render[2] }
+ txt1.destroy_texture()
+ txt1.create_text('$app.mouse_x,$app.mouse_y', 25)
+ txt1.create_texture()
+ r := app.mouse_x % 255
+ g := app.mouse_y % 255
+ color := u32(r << 24) | u32(g << 16) | 0xFF
+ txt1.bmp.color = color
+ txt1.draw_text_bmp(app.gg, app.mouse_x, app.mouse_y)
+ }
+ app.frame_c++
+ }
+ app.gg.end()
+}
+
+fn my_event_manager(mut ev gg.Event, mut app App_data) {
+ if ev.typ == .mouse_move {
+ app.mouse_x = int(ev.mouse_x)
+ app.mouse_y = int(ev.mouse_y)
+ }
+}
+
+[console]
+fn main() {
+ mut app := &App_data{
+ gg: 0
+ }
+ app.gg = gg.new_context(
+ width: win_width
+ height: win_height
+ create_window: true
+ window_title: 'Test TTF module'
+ user_data: app
+ bg_color: bg_color
+ frame_fn: draw_frame
+ event_fn: my_event_manager
+ init_fn: my_init
+ )
+ // load TTF fonts
+ for font_path in font_paths {
+ mut tf := ttf.TTF_File{}
+ tf.buf = os.read_bytes(font_path) or { panic(err) }
+ println('TrueTypeFont file [$font_path] len: $tf.buf.len')
+ tf.init()
+ println('Unit per EM: $tf.units_per_em')
+ app.tf << tf
+ }
+ // TTF render 0 Frame counter
+ app.ttf_render << &ttf.TTF_render_Sokol{
+ bmp: &ttf.BitMap{
+ tf: &(app.tf[0])
+ buf: unsafe { malloc_noscan(32000000) }
+ buf_size: (32000000)
+ color: 0xFF0000FF
+ // style: .raw
+ // use_font_metrics: true
+ }
+ }
+ // TTF render 1 Text Block
+ app.ttf_render << &ttf.TTF_render_Sokol{
+ bmp: &ttf.BitMap{
+ tf: &(app.tf[1])
+ // color : 0xFF0000_10
+ // style: .raw
+ // use_font_metrics: true
+ }
+ }
+ // TTF mouse position render
+ app.ttf_render << &ttf.TTF_render_Sokol{
+ bmp: &ttf.BitMap{
+ tf: &(app.tf[0])
+ }
+ }
+ // setup sokol_gfx
+ app.gg.run()
+}