~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/modules/filters/unicodertf.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *
 
3
 * unicodertf - SWFilter descendant to convert a double byte unicode file
 
4
 *                               to RTF tags
 
5
 *
 
6
 *
 
7
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
8
 *      CrossWire Bible Society
 
9
 *      P. O. Box 2528
 
10
 *      Tempe, AZ  85280-2528
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify it
 
13
 * under the terms of the GNU General Public License as published by the
 
14
 * Free Software Foundation version 2.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful, but
 
17
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
 * General Public License for more details.
 
20
 *
 
21
 */
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <unicodertf.h>
 
26
#include <swbuf.h>
 
27
 
 
28
SWORD_NAMESPACE_START
 
29
 
 
30
UnicodeRTF::UnicodeRTF() {
 
31
}
 
32
 
 
33
 
 
34
char UnicodeRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module)
 
35
{
 
36
        const unsigned char *from;
 
37
        char digit[10];
 
38
        unsigned long ch;
 
39
        signed short utf16;
 
40
        unsigned char from2[7];
 
41
 
 
42
        SWBuf orig = text;
 
43
 
 
44
        from = (const unsigned char *)orig.c_str();
 
45
 
 
46
        // -------------------------------
 
47
        for (text = ""; *from; from++) {
 
48
                ch = 0;
 
49
                //case: ANSI
 
50
                if ((*from & 128) != 128) {
 
51
                        text += *from;
 
52
                        continue;
 
53
                }
 
54
                //case: Invalid UTF-8 (illegal continuing byte in initial position)
 
55
                if ((*from & 128) && ((*from & 64) != 64)) {
 
56
                        continue;
 
57
                }
 
58
                //case: 2+ byte codepoint
 
59
                from2[0] = *from;
 
60
                from2[0] <<= 1;
 
61
                int subsequent;
 
62
                for (subsequent = 1; (from2[0] & 128) && (subsequent < 7); subsequent++) {
 
63
                        from2[0] <<= 1;
 
64
                        from2[subsequent] = from[subsequent];
 
65
                        from2[subsequent] &= 63;
 
66
                        ch <<= 6;
 
67
                        ch |= from2[subsequent];
 
68
                }
 
69
                subsequent--;
 
70
                from2[0] <<= 1;
 
71
                char significantFirstBits = 8 - (2+subsequent);
 
72
                
 
73
                ch |= (((short)from2[0]) << (((6*subsequent)+significantFirstBits)-8));
 
74
                from += subsequent;
 
75
                if (ch < 0x10000) {
 
76
                                utf16 = (signed short)ch;
 
77
                                text += '\\';
 
78
                                text += 'u';
 
79
                                sprintf(digit, "%d", utf16);
 
80
                                text += digit;
 
81
                                text += '?';
 
82
                         }
 
83
                        else {
 
84
                                utf16 = (signed short)((ch - 0x10000) / 0x400 + 0xD800);
 
85
                                text += '\\';
 
86
                                text += 'u';
 
87
                                sprintf(digit, "%d", utf16);
 
88
                                text += digit;
 
89
                                text += '?';
 
90
                                utf16 = (signed short)((ch - 0x10000) % 0x400 + 0xDC00);
 
91
                                text += '\\';
 
92
                                text += 'u';
 
93
                                sprintf(digit, "%d", utf16);
 
94
                                text += digit;
 
95
                                text += '?';
 
96
                        }
 
97
        }
 
98
           
 
99
        return 0;
 
100
}
 
101
 
 
102
SWORD_NAMESPACE_END