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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • Property svn:executable set to *
File size: 1.3 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
26if (php_sapi_name() != "cli") {
27    die("You have to run this program with php-cli!\n");
28}
29
30if ($argc < 3) {
31    die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
32}
33
34$cv = caca_create_canvas(0, 0);
35
36if (!caca_canvas_set_figfont($cv, $argv[1])) {
37    die("Could not open font\n");
38}
39
40$chars = unistr_to_ords($argv[2]);
41$color = 0;
42foreach ($chars as $c) {
43    caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
44    caca_put_figchar($cv, $c);
45}
46
47echo caca_export_string($cv, "utf8");
48
49?>
Note: See TracBrowser for help on using the repository browser.