~ubuntu-branches/ubuntu/jaunty/fqterm/jaunty

« back to all changes in this revision

Viewing changes to src/utilities/fqwcwidth.h

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing
  • Date: 2009-02-14 09:32:53 UTC
  • Revision ID: james.westby@ubuntu.com-20090214093253-s2e6544ox2aj79rj
Tags: upstream-0.9.3+svn632
ImportĀ upstreamĀ versionĀ 0.9.3+svn632

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   fqterm, a terminal emulator for both BBS and *nix.                    *
 
3
 *   Copyright (C) 2008 fqterm development group.                          *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.               *
 
19
 ***************************************************************************/
 
20
 
 
21
#ifndef FQTERM_FQWCWIDTH_H
 
22
#define FQTERM_FQWCWIDTH_H
 
23
 
 
24
#ifdef WIN32
 
25
#define uint32_t unsigned __int32
 
26
#define uint16_t unsigned __int16
 
27
typedef wchar_t UTF16;
 
28
#else  // WIN32
 
29
#include <stdio.h>
 
30
#include <stdint.h>
 
31
typedef uint16_t UTF16;
 
32
#endif  // WIN32
 
33
 
 
34
typedef char Verify_UTF16_Is_Two_Bytes[
 
35
    (sizeof(UTF16) == 2)? 1 : -1];
 
36
 
 
37
namespace FQTerm {
 
38
 
 
39
//const uint16_t URC = 0xfffd; // the Unicode Replacement Character
 
40
// TODO_UTF16: 0xfffd is of width 2, which is not desired.
 
41
const uint16_t URC = '?'; // use '?' instead of the Unicode Replacement Character
 
42
 
 
43
const int MAX_CELLS_PER_CHAR = 2;
 
44
 
 
45
int get_str_width(uint32_t ucs);
 
46
int get_str_width(const uint32_t *pwcs, size_t n);
 
47
int get_str_width(const UTF16 *utf16_str, size_t n);
 
48
int get_str_width(const UTF16 *utf16_str, size_t n, int max_width, int &element_consumed);
 
49
 
 
50
// Move p to next code point in max_n UTF16 characters.
 
51
// Return the width of the current code point.
 
52
int mk_advance_one_code_point(const UTF16 **p, const UTF16 *end);
 
53
 
 
54
// Move p to next code point in max_n UTF16 characters.
 
55
// Return the width.
 
56
int mk_advace_at_least_one_cell(const UTF16 **p, const UTF16 *end);
 
57
 
 
58
}  // namespace FQTerm 
 
59
 
 
60
#endif  // FQTERM_FQWCWIDTH_H