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

Last change on this file since 3172 was 3172, checked in by nico, 12 years ago
  • Add license headers in sample programs
  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/php5
2<?php
3/*
4 *  figfont.php      sample program for libcaca php binding
5 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
6 *
7 *  This program is free software. It comes without any warranty, to
8 *  the extent permitted by applicable law. You can redistribute it
9 *  and/or modify it under the terms of the Do What The Fuck You Want
10 *  To Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14function unistr_to_ords($str, $encoding = 'UTF-8'){       
15        $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
16        $result = array();
17
18        for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){       
19                $c = mb_substr($str, $i, 1, "UCS-4BE");                   
20                $val = unpack("N", $c);           
21                $result[] = $val[1];               
22        }       
23        return $result;
24}
25
26
27if ($argc < 3) {
28        die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
29}
30
31$cv = caca_create_canvas(0, 0);
32
33if (!caca_canvas_set_figfont($cv, $argv[1])) {
34        die("Could not open font\n");
35}
36
37$chars = unistr_to_ords($argv[2]);
38$color = 0;
39foreach ($chars as $c) {
40        caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
41        caca_put_figchar($cv, $c);
42}
43
44echo caca_export_string($cv, "utf8");
45
46?>
Note: See TracBrowser for help on using the repository browser.