source: libcaca/trunk/caca-php/examples/figfont.php @ 3135

Last change on this file since 3135 was 3135, checked in by nico, 12 years ago
  • Close php blocks in samples programs (add "?>")
  • Property svn:executable set to *
File size: 809 bytes
Line 
1#!/usr/bin/php5
2<?php
3
4function unistr_to_ords($str, $encoding = 'UTF-8'){       
5        $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
6        $result = array();
7
8        for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){       
9                $c = mb_substr($str, $i, 1, "UCS-4BE");                   
10                $val = unpack("N", $c);           
11                $result[] = $val[1];               
12        }       
13        return $result;
14}
15
16
17if ($argc < 3) {
18        die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
19}
20
21$cv = caca_create_canvas(0, 0);
22
23if (!caca_canvas_set_figfont($cv, $argv[1])) {
24        die("Could not open font\n");
25}
26
27$chars = unistr_to_ords($argv[2]);
28$color = 0;
29foreach ($chars as $c) {
30        caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
31        caca_put_figchar($cv, $c);
32}
33
34echo caca_export_string($cv, "utf8");
35
36?>
Note: See TracBrowser for help on using the repository browser.