Home | History | Annotate | Download | only in layout
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "xfa/src/fgas/src/fgas_base.h"
      8 #include "fx_unicode.h"
      9 void FX_TEXTLAYOUT_PieceSort(CFX_TPOArray& tpos, int32_t iStart, int32_t iEnd) {
     10   FXSYS_assert(iStart > -1 && iStart < tpos.GetSize());
     11   FXSYS_assert(iEnd > -1 && iEnd < tpos.GetSize());
     12   if (iStart >= iEnd) {
     13     return;
     14   }
     15   int32_t i = iStart, j = iEnd;
     16   FX_TPO *pCur = tpos.GetPtrAt(iStart), *pSort;
     17   int32_t v = pCur->pos;
     18   while (i < j) {
     19     while (j > i) {
     20       pSort = tpos.GetPtrAt(j);
     21       if (pSort->pos < v) {
     22         FX_TPO t = *pSort;
     23         *pSort = *pCur;
     24         *pCur = t;
     25         pCur = pSort;
     26         break;
     27       }
     28       j--;
     29     }
     30     while (i < j) {
     31       pSort = tpos.GetPtrAt(i);
     32       if (pSort->pos > v) {
     33         FX_TPO t = *pSort;
     34         *pSort = *pCur;
     35         *pCur = t;
     36         pCur = pSort;
     37         break;
     38       }
     39       i++;
     40     }
     41   }
     42   i--, j++;
     43   if (iStart < i) {
     44     FX_TEXTLAYOUT_PieceSort(tpos, iStart, i);
     45   }
     46   if (j < iEnd) {
     47     FX_TEXTLAYOUT_PieceSort(tpos, j, iEnd);
     48   }
     49 }
     50 static const FX_JAPCHARPROPERTYEX gs_FX_JapCharPropertysEx[] = {
     51     {0x3001, 0x13}, {0x3002, 0x13}, {0x3041, 0x23}, {0x3043, 0x23},
     52     {0x3045, 0x23}, {0x3047, 0x23}, {0x3049, 0x23}, {0x3063, 0x23},
     53     {0x3083, 0x23}, {0x3085, 0x23}, {0x3087, 0x23}, {0x308E, 0x23},
     54     {0x3095, 0x23}, {0x3096, 0x23}, {0x30A1, 0x23}, {0x30A3, 0x23},
     55     {0x30A5, 0x23}, {0x30A7, 0x23}, {0x30A9, 0x23}, {0x30C3, 0x23},
     56     {0x30E3, 0x23}, {0x30E5, 0x23}, {0x30E7, 0x23}, {0x30EE, 0x23},
     57     {0x30F5, 0x23}, {0x30F6, 0x23}, {0x30FB, 0x22}, {0x31F0, 0x23},
     58     {0x31F1, 0x23}, {0x31F2, 0x23}, {0x31F3, 0x23}, {0x31F4, 0x23},
     59     {0x31F5, 0x23}, {0x31F6, 0x23}, {0x31F7, 0x23}, {0x31F8, 0x23},
     60     {0x31F9, 0x23}, {0x31FA, 0x23}, {0x31FB, 0x23}, {0x31FC, 0x23},
     61     {0x31FD, 0x23}, {0x31FE, 0x23}, {0x31FF, 0x23},
     62 };
     63 FX_LPCJAPCHARPROPERTYEX FX_GetJapCharPropertyEx(FX_WCHAR wch) {
     64   int32_t iStart = 0;
     65   int32_t iEnd =
     66       sizeof(gs_FX_JapCharPropertysEx) / sizeof(FX_JAPCHARPROPERTYEX);
     67   while (iStart <= iEnd) {
     68     int32_t iMid = (iStart + iEnd) / 2;
     69     FX_WCHAR wJapChar = gs_FX_JapCharPropertysEx[iMid].wChar;
     70     if (wch == wJapChar) {
     71       return gs_FX_JapCharPropertysEx + iMid;
     72     } else if (wch < wJapChar) {
     73       iEnd = iMid - 1;
     74     } else {
     75       iStart = iMid + 1;
     76     }
     77   }
     78   return NULL;
     79 }
     80 FX_BOOL FX_AdjustJapCharDisplayPos(FX_WCHAR wch,
     81                                    FX_BOOL bMBCSCode,
     82                                    IFX_Font* pFont,
     83                                    FX_FLOAT fFontSize,
     84                                    FX_BOOL bVertical,
     85                                    CFX_PointF& ptOffset) {
     86   if (pFont == NULL || !bVertical) {
     87     return FALSE;
     88   }
     89   if (wch < 0x3001 || wch > 0x31FF) {
     90     return FALSE;
     91   }
     92   FX_LPCJAPCHARPROPERTYEX pJapChar = FX_GetJapCharPropertyEx(wch);
     93   if (pJapChar == NULL) {
     94     return FALSE;
     95   }
     96   CFX_Rect rtBBox;
     97   rtBBox.Reset();
     98   if (pFont->GetCharBBox(wch, rtBBox, bMBCSCode)) {
     99     switch (pJapChar->uAlign & 0xF0) {
    100       case FX_JAPCHARPROPERTYEX_Top:
    101         ptOffset.y = fFontSize * (1000 - rtBBox.height) / 1200.0f;
    102         break;
    103       case FX_JAPCHARPROPERTYEX_Middle:
    104         ptOffset.y = fFontSize * (1000 - rtBBox.height) / 6000.0f;
    105         break;
    106     }
    107     switch (pJapChar->uAlign & 0x0F) {
    108       case FX_JAPCHARPROPERTYEX_Center:
    109         ptOffset.x = fFontSize * (600 - rtBBox.right()) / 1000.0f;
    110         break;
    111       case FX_JAPCHARPROPERTYEX_Right:
    112         ptOffset.x = fFontSize * (950 - rtBBox.right()) / 1000.0f;
    113         break;
    114     }
    115   }
    116   return TRUE;
    117 }
    118