本來這個blog是記錄開發輸入法的點滴的,後來越來越雜,現在什麼都記錄了。

2012年4月11日 星期三

Doraemon in SVG format doraemon.svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   version="1.1"
   width="400"
   height="200" >

   <g transform="translate(226,56)">
    <path id="face" d="M -37 52 A 55 45 0 1 1 37 52 Z" style="fill:white;stroke:none" />
    <path id="head" d="M -37 52 A 55 45 0 1 1 37 52
                       L 47 52
                       A 64 64 0 1 0 -47 52
                       Z" style="fill:deepskyblue;stroke:black;stroke-width:2" />

    <circle id="nose" r="7" fill="red" stroke="black" stroke-width="2" />
    <ellipse id="lefteye" cx="-18" cy="-18" rx="18" ry="18" fill="white" stroke="black" stroke-width="2"/>
    <circle id="lefteye_center" r="2" cx="-9" cy="-10" fill="black" stroke="black" stroke-width="2" />
    <ellipse id="righteye" cx="18" cy="-18" rx="18" ry="18" fill="white" stroke="black" stroke-width="2"/>
    <circle id="righteye_center" r="2" cx="9" cy="-10" fill="black" stroke="black" stroke-width="2" />
    <line id="mouth_top_vert" x1="0" y1="7" x2="0" y2="45" stroke="black" stroke-width="2" />
    <path id="mouth" d="M -32,29 A 40 40 0 0 0 32 29" style="fill:none;stroke:black;stroke-width:2" />

    <path id="moustache_left_top" d="M -44 24 l 21 -6" style="stroke:black;stroke-width:2;fill:none"/>
    <path id="moustache_left_mid" d="M -44 12 l 22 0"  style="stroke:black;stroke-width:2;fill:none"/>
    <path id="moustache_left_btm" d="M -44  0 l 21 6"  style="stroke:black;stroke-width:2;fill:none"/>

    <path id="moustache_right_top" d="M 44 24 l -21 -6" style="stroke:black;stroke-width:2;fill:none"/>
    <path id="moustache_right_mid" d="M 44 12 l -22 0"  style="stroke:black;stroke-width:2;fill:none"/>
    <path id="moustache_right_btm" d="M 44  0 l -21 6"  style="stroke:black;stroke-width:2;fill:none"/>

    <path id="head_body_separator" d="M 47 52
                                      A 2 2 0 1 1 47 62
                                      L -47 62
                                      A 2 2 0 0 1 -47 52
                                      Z" style="fill:red;stroke:black;stroke-width:2" />

    <path id="body_outline" d="M -47 62 L -69 77 A 15 15 1 0 1 -57 98 L -47 89 L -47 127 L -7 127
                               A 2 2 0 1 1 7 127 L 47 127 L 47 89 L 57 98 A 15 15 1 0 1 69 77 L 47 62 Z"
                            style="fill:deepskyblue;stroke:black;stroke-width:2" />

    <path id="body_outline" d="M -30 62 A 35 35 1 1 0 30 62 Z"
                            style="fill:white;stroke:black;stroke-width:2" />

    <path id="pocket" d="M -25 80 A 25 25 1 0 0 25 80 Z"
                            style="fill:none;stroke:black;stroke-width:2" />
    <g id="ring">
      <path id="ring_outline" d="M -6 62 A 8 8 0 0 0 0 74 L 0 68 L 0 74 A 8 8 0 0 0 6 62 Z"
                              style="fill:yellow;stroke:black;stroke-width:2;" />
      <circle id="ring_center" r="2" cx="0" cy="68" style="fill:black;stroke:none" />
    </g>

    <path id="left_hand" d="M -69 77 A 15 15 1 0 1 -57 98 A 15 15 1 1 1 -69 77"
                            style="fill:white;stroke:black;stroke-width:2" />

    <path id="left_foot" d="M -8 140 A 8 8 0 0 0 -7 127 L -47 127 A 8 8 0 0 0 -50 140 Z"
                            style="fill:white;stroke:black;stroke-width:2" />

    <path id="right_hand" d="M 69 77 A 15 15 1 0 0 57 98 A 15 15 1 1 0 69 77"
                            style="fill:white;stroke:black;stroke-width:2" />

    <path id="right_foot" d="M 8 140 A 8 8 0 0 1 7 127 L 47 127 A 8 8 0 0 1 50 140 Z"
                            style="fill:white;stroke:black;stroke-width:2" />

  </g>
</svg>

2012年3月29日 星期四

Hong Kong Emblem Simplest SVG (hollow) 香港旗 香港徽號 SVG (空心).

>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  version="1.0" width="450" height="450" >

  <style type="text/css" >
    <![CDATA[
      text.emblemChars {
          fill:red; stroke:red; text-anchor:middle; font-size:35px; font-family: SimHei;
      }
    ]]>
  </style>

  <defs>
      <path id="petalOutline" d="M 0 0
               A 20 25 0 1 1 0 -135
               A 30 30 0 0 0 0 -90
               A 30 30 0 0 1 0 -45
               A 30 30 0 0 0 0 0 z"
               stroke="none" fill="#black" />

      <g id="petalDetails">
        <polygon fill="red" stroke="none"
                points="0,-12 3,-3.5 12,-3.5 5,2 7.5,10.5 0,5.5 -7.5,10.5 -5,2 -12,-3.5 -3,-3.5"
                transform="translate(-20,-75) rotate(30)" />
        <path d="M 0 0
                 A 60 60 0 0 1 -30 -60"
                 stroke="red" fill="none" stroke-width="1px" />
      </g>

  </defs>

  <g transform="translate(225, 225)">
    <defs>
      <mask id="myMask" maskUnits="userSpaceOnUse" x="-180" y="-180" width="360" height="360">
        <!-- by default the whole rectangle is a big hole -->
      
        <!-- add a white rectangle so that the whole area is not a hole -->
        <rect x="-180" y="-180" width="360" height="360" fill="#fff" />
      
        <!-- fill the parts you think should become hollow with white coor -->
        <use xlink:href="#petalOutline" transform="rotate(13.48)" />
        <use xlink:href="#petalOutline" transform="rotate(85.48)" />
        <use xlink:href="#petalOutline" transform="rotate(157.48)" />
        <use xlink:href="#petalOutline" transform="rotate(229.48)" />
        <use xlink:href="#petalOutline" transform="rotate(301.48)" />
      </mask>
    </defs>

    <circle fill="none" stroke="red" cx="0"  cy="0"  r="220"/>
    <g mask="url(#myMask)">
      <circle fill="red" stroke="none" cx="0"  cy="0"  r="180"/>
    </g>
    <use xlink:href="#petalDetails" transform="rotate(13.48)" />
    <use xlink:href="#petalDetails" transform="rotate(85.48)" />
    <use xlink:href="#petalDetails" transform="rotate(157.48)" />
    <use xlink:href="#petalDetails" transform="rotate(229.48)" />
    <use xlink:href="#petalDetails" transform="rotate(301.48)" />

    <text class="emblemChars" y="-186" transform="rotate(-110.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate( -93.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate( -76.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate( -59.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate( -42.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate( -25.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(  -8.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(   8.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(  25.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(  42.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(  59.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(  76.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate(  93.5)"></text>
    <text class="emblemChars" y="-186" transform="rotate( 110.5)"></text>

    <text class="emblemChars" y="-186" transform="rotate(-125.0)"></text>
    <text class="emblemChars" y="-186" transform="rotate( 125.0)"></text>

    <text class="emblemChars" y="+215" transform="rotate( 33.0)">H</text>
    <text class="emblemChars" y="+215" transform="rotate( 23.7)">O</text>
    <text class="emblemChars" y="+215" transform="rotate( 14.3)">N</text>
    <text class="emblemChars" y="+215" transform="rotate(  5.0)">G</text>
    <text class="emblemChars" y="+215" transform="rotate( -5.0)">K</text>
    <text class="emblemChars" y="+215" transform="rotate(-14.3)">O</text>
    <text class="emblemChars" y="+215" transform="rotate(-23.7)">N</text>
    <text class="emblemChars" y="+215" transform="rotate(-33.0)">G</text>
 </g>
</svg>

2011年2月9日 星期三

C++ program to remove C/C++ style comments, while keep string content intact and line numbers of code unchnaged...

#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string>
#include <iostream>
#include <vector>
#include <string>

int my_fgets(std::string &str, FILE *fp, unsigned char to_remove_comments) {
    // read one line from file. if end of file return 0 otherwise return 1
    int ret=1;
    static unsigned char prev_linebreak;
    unsigned char ch;

    str.clear();

    while(1) {
        ch = fgetc(fp);

        if (feof(fp)) {
            prev_linebreak='\0';
            if (str.empty())
                ret=0;
            break;
        }

        if (ch=='\r') {
            prev_linebreak='\r';
            break;
        }

        if (ch=='\n') {
            if (prev_linebreak=='\r') {
                prev_linebreak='\0';
                continue;
            } else {
                prev_linebreak='\n';
                break;
            }
        }
        str+=ch;
    }

    if (to_remove_comments)
    {
        std::string tmpstr=str;
        
        static enum IN_COMMENT_T {
            IN_COMMENT_NOT,
            IN_COMMENT_WAIT_FOR_STAR_SLASH,
            IN_COMMENT_DOUBLE_QUOTE,
        } in_comment = IN_COMMENT_NOT;
        const char *p, *p_limit, *p_start;
        
        str.clear();
        p_start = tmpstr.c_str();
        p_limit = p_start + tmpstr.length();
        
        for(p=p_start; p<p_limit; p++) {
            switch(in_comment) {
            case IN_COMMENT_NOT:
                if (strncmp(p, "//", 2)==0) {
                    p=p_limit-1;
                    continue;
                } else if (strncmp(p, "/*", 2)==0) {
                    in_comment=IN_COMMENT_WAIT_FOR_STAR_SLASH;
                    p+=(sizeof("/*")-1)-1;
                } else if (*p=='"') {
                    // avoid case like '"'
                    if (p==p_start || *(p-1)!='\'')
                        in_comment=IN_COMMENT_DOUBLE_QUOTE;
                }
                break;
            case IN_COMMENT_WAIT_FOR_STAR_SLASH:
                if (strncmp(p, "*/", 2)==0) {
                    in_comment=IN_COMMENT_NOT;
                    p+=sizeof("*/")-1;
                }
                break;
            case IN_COMMENT_DOUBLE_QUOTE:
                if (*p=='"') {
                    // need to count how many '\' in the front. If it is even number then end of quote!
                    const char *q;
                    for(q=p-1; q>=p_start && *q=='\\'; q--);
                    if ((p-q)&1) {
                        // note (p-q)-1 is the number of '\\' before '"'.
                        // if ((p-q)-1) is odd, the " is escaped.
                        // if ((p-q)-1) is even, the " is a real close quotoation.
                        in_comment=IN_COMMENT_NOT;
                    }
                }
                break;
            default:
                break;
            }
        
            if (in_comment==IN_COMMENT_NOT || in_comment==IN_COMMENT_DOUBLE_QUOTE)
                str = str+*p;
        }
        
        if (ret==0)
            in_comment = IN_COMMENT_NOT;
    }

    return ret;
}

int 
main(int argc, char **argv) {
    FILE *fp=NULL;
    std::string str;

    if (argc!=2) {
        fprintf(stderr, "remove C style comment in a text file and show in stdout\n");
        fprintf(stderr, "usage: %s file\n", argv[0]);
        goto MAIN_ERROR;
    }

    fp=fopen(argv[1], "rb");

    if (fp==NULL)  {
        fprintf(stderr, "error in open %s\n", argv[1]);
        goto MAIN_ERROR;
    }

    while(my_fgets(str, fp, 1))
        fprintf(stderr, "%s\n", str.c_str());

                    
MAIN_ERROR:
    if (fp)
        fclose(fp);

    return 0;

}

2011年1月23日 星期日

how to download audio from rthk server using wget?

wget --user-agent="NSPlayer/4.1.0.3938" --header="Pragma: \
no-cache,\
rate=1.000000,\
stream-time=240800,\
stream-offset=4294967295:4294967295,\
request-context=4,\
max-duration=2151082448,\
xPlayStrm=1,\
xClientGUID={3300AD50-2C39-46c0-AE0A-6420211E86C2},\
stream-switch-count=1,\
stream-switch-entry=ffff:1:0" \
http://202.177.192.111/rthk/radio1/20110122/2011012214.asf

2010年11月2日 星期二

iPod HID Report Descriptor, what exactly is the content?

I am working on iPod HID interface recently.

As the first thing to do when working on HID interface, the lsusb -vv is used.

Here is the result:
Bus 002 Device 005: ID 05ac:1291 Apple, Inc. iPod Touch 1.Gen
...
Interface Descriptor:
  bLength                 9
  bDescriptorType         4
  bInterfaceNumber        2
  bAlternateSetting       0
  bNumEndpoints           1
  bInterfaceClass         3 Human Interface Device
  bInterfaceSubClass      0 No Subclass
  bInterfaceProtocol      0 None
  iInterface              0
    HID Device Descriptor:
      bLength                 9
      bDescriptorType        33
      bcdHID               1.11
      bCountryCode            0 Not supported
      bNumDescriptors         1
      bDescriptorType        34 Report
      wDescriptorLength     208
     Report Descriptors:
       ** UNAVAILABLE **

It seems to me that wDescriptorLength is 208. I am not sure why the Report Descriptors is UNAVAILABLE.

According to this link: which somehow make the Report Descriptors available, the 208 bytes are:
06 00 ff 09 01 a1 01 75 08 26 80 00 15 00 09 01 85 01 95 05 82 02 01 09 01 85 02
95 09 82 02 01 09 01 85 03 95 0d 82 02 01 09 01 85 04 95 11 82 02 01 09 01 85 05
95 19 82 02 01 09 01 85 06 95 31 82 02 01 09 01 85 07 95 5f 82 02 01 09 01 85 08
95 c1 82 02 01 09 01 85 09 96 01 01 82 02 01 09 01 85 0a 96 81 01 82 02 01 09 01
85 0b 96 01 02 82 02 01 09 01 85 0c 96 ff 02 82 02 01 09 01 85 0d 95 05 92 02 01
09 01 85 0e 95 09 92 02 01 09 01 85 0f 95 0d 92 02 01 09 01 85 10 95 11 92 02 01
09 01 85 11 95 19 92 02 01 09 01 85 12 95 31 92 02 01 09 01 85 13 95 5f 92 02 01
09 01 85 14 95 c1 92 02 01 09 01 85 15 95 ff 92 02 01 c0

With the hidrd-convert tool, the above is parsed as shown below:
Usage Page (FF00h), ; FF00h, vendor-defined
Usage (01h),
Collection (Application),
 Report Size (8),
 Logical Maximum (128),
 Logical Minimum (0),
 Usage (01h), ReportID( 0x1), ReportCount(  5),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x2), ReportCount(  9),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x3), ReportCount( 13),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x4), ReportCount( 17),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x5), ReportCount( 25),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x6), ReportCount( 49),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x7), ReportCount( 95),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x8), ReportCount(193),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0x9), ReportCount(257),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0xa), ReportCount(385),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0xb), ReportCount(513),  Input(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0xc), ReportCount(767),  Input(Variable, Buffered Bytes),

 Usage (01h), ReportID( 0xd), ReportCount(  5), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0xe), ReportCount(  9), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID( 0xf), ReportCount( 13), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID(0x10), ReportCount( 17), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID(0x11), ReportCount( 25), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID(0x12), ReportCount( 49), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID(0x13), ReportCount( 95), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID(0x14), ReportCount(193), Output(Variable, Buffered Bytes),
 Usage (01h), ReportID(0x15), ReportCount(255), Output(Variable, Buffered Bytes),
End Collection

However, with a 3rd party library that I used for the embedded system I am working on, I got a completely different result.

The size of descriptor is 96 bytes!!!!!!!!!!! (but not 208 bytes for lsusb -vv):
0600 ff09 01a1 0175 0826 8000 1500 0901
8501 950c 8202 0109 0185 0295 0e82 0201
0901 8503 9514 8202 0109 0185 0495 3f82
0201 0901 8505 9508 9202 0109 0185 0695
0a92 0201 0901 8507 950e 9202 0109 0185
0895 1492 0201 0901 8509 953f 9202 01c0

After parsing:
Usage Page (FF00h),                     ; FF00h, vendor-defined
Usage (01h),
Collection (Application),
  Report Size (8),
  Logical Maximum (128),
  Logical Minimum (0),

  Usage (01h), Report ID (1), Report Count (12), Input  (Variable, Buffered Bytes),
  Usage (01h), Report ID (2), Report Count (14), Input  (Variable, Buffered Bytes),
  Usage (01h), Report ID (3), Report Count (20), Input  (Variable, Buffered Bytes),
  Usage (01h), Report ID (4), Report Count (63), Input  (Variable, Buffered Bytes),

  Usage (01h), Report ID (5), Report Count (8),  Output (Variable, Buffered Bytes),
  Usage (01h), Report ID (6), Report Count (10), Output (Variable, Buffered Bytes),
  Usage (01h), Report ID (7), Report Count (14), Output (Variable, Buffered Bytes),
  Usage (01h), Report ID (8), Report Count (20), Output (Variable, Buffered Bytes),
  Usage (01h), Report ID (9), Report Count (63), Output (Variable, Buffered Bytes),
End Collection

Which one should I believe???????