LCOV - code coverage report
Current view: directory - intl/lwbrk/src - nsPangoBreaker.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 22 0 0.0 %
Date: 2012-06-02 Functions: 1 0 0.0 %

       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
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      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.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  * - Theppitak Karoonboonyanan <thep@linux.thai.net>
      24                 :  *
      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.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "nsComplexBreaker.h"
      40                 : 
      41                 : #include <pango/pango-break.h>
      42                 : #include "nsUTF8Utils.h"
      43                 : #include "nsString.h"
      44                 : #include "nsTArray.h"
      45                 : 
      46                 : void
      47               0 : NS_GetComplexLineBreaks(const PRUnichar* aText, PRUint32 aLength,
      48                 :                         PRUint8* aBreakBefore)
      49                 : {
      50               0 :   NS_ASSERTION(aText, "aText shouldn't be null");
      51                 : 
      52               0 :   memset(aBreakBefore, false, aLength * sizeof(PRUint8));
      53                 : 
      54               0 :   nsAutoTArray<PangoLogAttr, 2000> attrBuffer;
      55               0 :   if (!attrBuffer.AppendElements(aLength + 1))
      56                 :     return;
      57                 : 
      58               0 :   NS_ConvertUTF16toUTF8 aUTF8(aText, aLength);
      59                 : 
      60               0 :   const gchar* p = aUTF8.Data();
      61               0 :   const gchar* end = p + aUTF8.Length();
      62               0 :   PRUint32     u16Offset = 0;
      63                 : 
      64               0 :   static PangoLanguage* language = pango_language_from_string("en");
      65                 : 
      66               0 :   while (p < end)
      67                 :   {
      68               0 :     PangoLogAttr* attr = attrBuffer.Elements();
      69               0 :     pango_get_log_attrs(p, end - p, -1, language, attr, attrBuffer.Length());
      70                 : 
      71               0 :     while (p < end)
      72                 :     {
      73               0 :       aBreakBefore[u16Offset] = attr->is_line_break;
      74               0 :       if (NS_IS_LOW_SURROGATE(aText[u16Offset]))
      75               0 :         aBreakBefore[++u16Offset] = false; // Skip high surrogate
      76               0 :       ++u16Offset;
      77                 : 
      78                 :       bool err;
      79               0 :       PRUint32 ch = UTF8CharEnumerator::NextChar(&p, end, &err);
      80               0 :       ++attr;
      81                 : 
      82               0 :       if (ch == 0 || err) {
      83                 :         // pango_break (pango 1.16.2) only analyses text before the
      84                 :         // first NUL (but sets one extra attr). Workaround loop to call
      85                 :         // pango_break again to analyse after the NUL is done somewhere else
      86                 :         // (gfx/thebes/gfxPangoFonts.cpp: SetupClusterBoundaries()).
      87                 :         // So, we do the same here for pango_get_log_attrs.
      88               0 :         break;
      89                 :       }
      90                 :     }
      91                 :   }
      92                 : }
      93                 : 

Generated by: LCOV version 1.7