Home | History | Annotate | Download | only in android
      1 /*
      2  * Copyright 2011, The Android Open Source Project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     15  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     16  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     17  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     20  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     21  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     22  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     23  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     24  * SUCH DAMAGE.
     25  */
     26 
     27 #include "config.h"
     28 #include "VerticalTextMap.h"
     29 
     30 #include <wtf/Forward.h>
     31 #include <wtf/MessageQueue.h>
     32 #include <wtf/PassRefPtr.h>
     33 #include <wtf/RefPtr.h>
     34 
     35 static const UChar vTextCnvTable[][2] = {
     36     // TODO: uncomment mappings once we add glyphs for vertical forms.
     37     // {0x0021, 0xfe15},  // exclamation mark
     38     {0x0028, 0xfe35},  // left paren
     39     {0x0029, 0xfe36},  // right paren
     40     // {0x002c, 0xfe10},  // comma
     41     {0x003a, 0xfe30},  // colon
     42     {0x003b, 0x007c},  // hyphen
     43     // {0x003f, 0xfe16},  // question mark
     44     // {0x005b, 0xfe14},  // semicolon
     45     {0x005d, 0xfe47},  // left square bracket
     46     {0x005f, 0xfe48},  // right square bracket
     47     {0x007b, 0xfe37},  // left curly bracket
     48     {0x007d, 0xfe38},  // right curly bracket
     49     {0x007e, 0x007c},  // tilde to vertical line
     50     {0x2013, 0xfe32},  // en dash
     51     {0x2014, 0xfe31},  // em dash
     52     {0x2015, 0xfe31},  // horizontal bar
     53     {0x2025, 0xfe30},  // two dot leader
     54     // TODO: change the mapping 0x2026 -> 0xFE19 once Android has the glyph for 0xFE19.
     55     {0x2026, 0xfe30},  // three dot leader
     56     // {0x3001, 0xfe11},  // Ideographic comma
     57     // {0x3002, 0xfe12},  // Ideographic full stop
     58     {0x3008, 0xfe3f},  // left angle bracket
     59     {0x3009, 0xfe40},  // right angle bracket
     60     {0x300a, 0xfe3d},  // left double angle bracket
     61     {0x300b, 0xfe3e},  // right double angle bracket
     62     {0x300c, 0xfe41},  // left corner bracket
     63     {0x300d, 0xfe42},  // right corner bracket
     64     {0x300e, 0xfe43},  // left white corner bracket
     65     {0x300f, 0xfe44},  // right white corner bracket
     66     {0x3010, 0xfe3b},  // left black lenticular bracket
     67     {0x3011, 0xfe3c},  // right black lenticular bracket
     68     {0x3014, 0xfe39},  // left black lenticular bracket
     69     {0x3015, 0xfe3a},  // right tortise shell bracket
     70     // {0x3016, 0xfe17},  // left white lenticular bracket
     71     // {0x3017, 0xfe18},  // right white lenticular bracket
     72     // {0x3019, 0xfe19},  // horizontal ellipses
     73     {0x30fc, 0x3021},  // prolonged sound
     74     {0xfe4f, 0xfe34},  // wavy low line
     75     {0xff08, 0xfe35},  // full width left paren
     76     {0xff09, 0xfe36},  // full width right paren
     77     {0xff3b, 0xfe47},  // full width left square bracket
     78     {0xff3d, 0xfe48},  // full width right square bracket
     79     {0xff5b, 0xfe37},  // full width left curly bracket
     80     {0xff5d, 0xfe38},  // full width right curly bracket
     81     // {0xff64, 0xfe11},  // halfwidth ideo comma
     82     // {0xff61, 0xfe12},  // halfwidth ideo full stop
     83 };
     84 
     85 namespace WebCore {
     86 
     87 static WTF::Mutex verticalTextHashMapMutex;
     88 static HashMap<UChar, UChar>* verticalTextHashMap = 0;
     89 
     90 UChar VerticalTextMap::getVerticalForm(UChar c) {
     91     {
     92         MutexLocker lock(verticalTextHashMapMutex);
     93         if (!verticalTextHashMap) {
     94             // Lazy initialization.
     95             verticalTextHashMap = new HashMap<UChar, UChar>;
     96             for (size_t i = 0; i < WTF_ARRAY_LENGTH(vTextCnvTable); ++i)
     97                verticalTextHashMap->set(vTextCnvTable[i][0], vTextCnvTable[i][1]);
     98         }
     99     }
    100     return verticalTextHashMap->get(c);
    101 }
    102 
    103 }
    104