1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Theppitak Karoonboonyanan <thep@linux.thai.net>.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
23 * - Theppitak Karoonboonyanan <thep@linux.thai.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsComplexBreaker.h"
41 #include <pango/pango-break.h>
42 #include "nsUTF8Utils.h"
47 NS_GetComplexLineBreaks(const PRUnichar
* aText
, PRUint32 aLength
,
48 PRPackedBool
* aBreakBefore
)
50 NS_ASSERTION(aText
, "aText shouldn't be null");
52 memset(aBreakBefore
, PR_FALSE
, aLength
* sizeof(PRPackedBool
));
54 nsAutoTArray
<PangoLogAttr
, 2000> attrBuffer
;
55 if (!attrBuffer
.AppendElements(aLength
+ 1))
58 NS_ConvertUTF16toUTF8
aUTF8(aText
, aLength
);
60 const gchar
* p
= aUTF8
.Data();
61 const gchar
* end
= p
+ aUTF8
.Length();
62 PRUint32 u16Offset
= 0;
64 static PangoLanguage
* language
= pango_language_from_string("en");
68 PangoLogAttr
* attr
= attrBuffer
.Elements();
69 pango_get_log_attrs(p
, end
- p
, -1, language
, attr
, attrBuffer
.Length());
73 aBreakBefore
[u16Offset
] = attr
->is_line_break
;
74 if (NS_IS_LOW_SURROGATE(aText
[u16Offset
]))
75 aBreakBefore
[++u16Offset
] = PR_FALSE
; // Skip high surrogate
78 PRUint32 ch
= UTF8CharEnumerator::NextChar(&p
, end
);
82 // pango_break (pango 1.16.2) only analyses text before the
83 // first NUL (but sets one extra attr). Workaround loop to call
84 // pango_break again to analyse after the NUL is done somewhere else
85 // (gfx/thebes/src/gfxPangoFonts.cpp: SetupClusterBoundaries()).
86 // So, we do the same here for pango_get_log_attrs.