Advertisement
Guest User

Untitled

a guest
Nov 10th, 2010
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 25.21 KB | None | 0 0
  1. Index: x11-fonts/libXft/files/patch-ubuntu-lcd-filter
  2. ===================================================================
  3. RCS file: x11-fonts/libXft/files/patch-ubuntu-lcd-filter
  4. diff -N x11-fonts/libXft/files/patch-ubuntu-lcd-filter
  5. --- /dev/null   1 Jan 1970 00:00:00 -0000
  6. +++ x11-fonts/libXft/files/patch-ubuntu-lcd-filter  6 Jun 2010 15:40:11 -0000
  7. @@ -0,0 +1,843 @@
  8. +--- src/xftdpy.c
  9. ++++ src/xftdpy.c
  10. +@@ -369,6 +369,10 @@
  11. +   goto bail1;
  12. +     if (!_XftDefaultInitInteger (dpy, pat, FC_RGBA))
  13. +   goto bail1;
  14. ++#ifdef FC_LCD_FILTER
  15. ++    if (!_XftDefaultInitInteger (dpy, pat, FC_LCD_FILTER))
  16. ++  goto bail1;
  17. ++#endif
  18. +     if (!_XftDefaultInitBool (dpy, pat, FC_ANTIALIAS))
  19. +   goto bail1;
  20. + #ifdef FC_EMBOLDEN
  21. +@@ -521,6 +525,14 @@
  22. +                 XftDefaultGetInteger (dpy, FC_RGBA, screen,
  23. +                           subpixel));
  24. +     }
  25. ++#ifdef FC_LCD_FILTER
  26. ++    if (FcPatternGet (pattern, FC_LCD_FILTER, 0, &v) == FcResultNoMatch)
  27. ++    {
  28. ++  FcPatternAddInteger (pattern, FC_LCD_FILTER,
  29. ++               XftDefaultGetInteger (dpy, FC_LCD_FILTER, screen,
  30. ++                         FC_LCD_DEFAULT));
  31. ++    }
  32. ++#endif
  33. +     if (FcPatternGet (pattern, FC_MINSPACE, 0, &v) == FcResultNoMatch)
  34. +     {
  35. +   FcPatternAddBool (pattern, FC_MINSPACE,
  36. +--- src/xftfreetype.c
  37. ++++ src/xftfreetype.c
  38. +@@ -469,6 +469,21 @@
  39. +   goto bail1;
  40. +     }
  41. +    
  42. ++#ifdef FC_LCD_FILTER
  43. ++    /*
  44. ++     * Get lcd_filter value
  45. ++     */
  46. ++    switch (FcPatternGetInteger (pattern, FC_LCD_FILTER, 0, &fi->lcd_filter)) {
  47. ++    case FcResultNoMatch:
  48. ++  fi->lcd_filter = FC_LCD_DEFAULT;
  49. ++  break;
  50. ++    case FcResultMatch:
  51. ++  break;
  52. ++    default:
  53. ++  goto bail1;
  54. ++    }
  55. ++#endif
  56. ++    
  57. +     /*
  58. +      * Get matrix and transform values
  59. +      */
  60. +--- src/xftglyphs.c
  61. ++++ src/xftglyphs.c
  62. +@@ -21,27 +21,18 @@
  63. +  */
  64. +
  65. + #include "xftint.h"
  66. +-#include <freetype/ftoutln.h>
  67. +
  68. + #if HAVE_FT_GLYPHSLOT_EMBOLDEN
  69. + #include <freetype/ftsynth.h>
  70. + #endif
  71. +
  72. +-static const int    filters[3][3] = {
  73. +-    /* red */
  74. +-#if 0
  75. +-{    65538*4/7,65538*2/7,65538*1/7 },
  76. +-    /* green */
  77. +-{    65536*1/4, 65536*2/4, 65537*1/4 },
  78. +-    /* blue */
  79. +-{    65538*1/7,65538*2/7,65538*4/7 },
  80. ++#if FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH < 20202
  81. ++#  error  "FreeType 2.2.2 or later required to compile this version of libXft"
  82. + #endif
  83. +-{    65538*9/13,65538*3/13,65538*1/13 },
  84. +-    /* green */
  85. +-{    65538*1/6, 65538*4/6, 65538*1/6 },
  86. +-    /* blue */
  87. +-{    65538*1/13,65538*3/13,65538*9/13 },
  88. +-};
  89. ++
  90. ++#include FT_OUTLINE_H
  91. ++#include FT_LCD_FILTER_H
  92. ++#include FT_SYNTHESIS_H
  93. +
  94. + /*
  95. +  * Validate the memory info for a font
  96. +@@ -69,6 +60,295 @@
  97. +       font->glyph_memory, glyph_memory);
  98. + }
  99. +
  100. ++
  101. ++/* we sometimes need to convert the glyph bitmap in a FT_GlyphSlot
  102. ++ * into a different format. For example, we want to convert a
  103. ++ * FT_PIXEL_MODE_LCD or FT_PIXEL_MODE_LCD_V bitmap into a 32-bit
  104. ++ * ARGB or ABGR bitmap.
  105. ++ *
  106. ++ * this function prepares a target descriptor for this operation.
  107. ++ *
  108. ++ * input :: target bitmap descriptor. The function will set its
  109. ++ *          'width', 'rows' and 'pitch' fields, and only these
  110. ++ *
  111. ++ * slot  :: the glyph slot containing the source bitmap. this
  112. ++ *          function assumes that slot->format == FT_GLYPH_FORMAT_BITMAP
  113. ++ *
  114. ++ * mode  :: the requested final rendering mode. supported values are
  115. ++ *          MONO, NORMAL (i.e. gray), LCD and LCD_V
  116. ++ *
  117. ++ * the function returns the size in bytes of the corresponding buffer,
  118. ++ * it's up to the caller to allocate the corresponding memory block
  119. ++ * before calling _fill_xrender_bitmap
  120. ++ *
  121. ++ * it also returns -1 in case of error (e.g. incompatible arguments,
  122. ++ * like trying to convert a gray bitmap into a monochrome one)
  123. ++ */
  124. ++static int
  125. ++_compute_xrender_bitmap_size( FT_Bitmap*      target,
  126. ++                              FT_GlyphSlot    slot,
  127. ++                              FT_Render_Mode  mode )
  128. ++{
  129. ++    FT_Bitmap*  ftbit;
  130. ++    int         width, height, pitch;
  131. ++
  132. ++    if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
  133. ++        return -1;
  134. ++
  135. ++    // compute the size of the final bitmap
  136. ++    ftbit  = &slot->bitmap;
  137. ++
  138. ++    width  = ftbit->width;
  139. ++    height = ftbit->rows;
  140. ++    pitch  = (width+3) & ~3;
  141. ++
  142. ++    switch ( ftbit->pixel_mode )
  143. ++    {
  144. ++    case FT_PIXEL_MODE_MONO:
  145. ++        if ( mode == FT_RENDER_MODE_MONO )
  146. ++        {
  147. ++            pitch = (((width+31) & ~31) >> 3);
  148. ++            break;
  149. ++        }
  150. ++        /* fall-through */
  151. ++
  152. ++    case FT_PIXEL_MODE_GRAY:
  153. ++        if ( mode == FT_RENDER_MODE_LCD   ||
  154. ++             mode == FT_RENDER_MODE_LCD_V )
  155. ++        {
  156. ++          /* each pixel is replicated into a 32-bit ARGB value */
  157. ++          pitch = width*4;
  158. ++        }
  159. ++        break;
  160. ++
  161. ++    case FT_PIXEL_MODE_LCD:
  162. ++        if ( mode != FT_RENDER_MODE_LCD )
  163. ++            return -1;
  164. ++
  165. ++        /* horz pixel triplets are packed into 32-bit ARGB values */
  166. ++        width   /= 3;
  167. ++        pitch    = width*4;
  168. ++        break;
  169. ++
  170. ++    case FT_PIXEL_MODE_LCD_V:
  171. ++        if ( mode != FT_RENDER_MODE_LCD_V )
  172. ++            return -1;
  173. ++
  174. ++        /* vert pixel triplets are packed into 32-bit ARGB values */
  175. ++        height  /= 3;
  176. ++        pitch    = width*4;
  177. ++        break;
  178. ++
  179. ++    default:  /* unsupported source format */
  180. ++        return -1;
  181. ++    }
  182. ++
  183. ++    target->width  = width;
  184. ++    target->rows   = height;
  185. ++    target->pitch  = pitch;
  186. ++    target->buffer = NULL;
  187. ++
  188. ++    return pitch * height;
  189. ++}
  190. ++
  191. ++/* this functions converts the glyph bitmap found in a FT_GlyphSlot
  192. ++ * into a different format (see _compute_xrender_bitmap_size)
  193. ++ *
  194. ++ * you should call this function after _compute_xrender_bitmap_size
  195. ++ *
  196. ++ * target :: target bitmap descriptor. Note that its 'buffer' pointer
  197. ++ *           must point to memory allocated by the caller
  198. ++ *
  199. ++ * slot   :: the glyph slot containing the source bitmap
  200. ++ *
  201. ++ * mode   :: the requested final rendering mode
  202. ++ *
  203. ++ * bgr    :: boolean, set if BGR or VBGR pixel ordering is needed
  204. ++ */
  205. ++static void
  206. ++_fill_xrender_bitmap( FT_Bitmap*      target,
  207. ++                      FT_GlyphSlot    slot,
  208. ++                      FT_Render_Mode  mode,
  209. ++                      int             bgr )
  210. ++{
  211. ++    FT_Bitmap*   ftbit = &slot->bitmap;
  212. ++
  213. ++    {
  214. ++        unsigned char*   srcLine   = ftbit->buffer;
  215. ++        unsigned char*   dstLine   = target->buffer;
  216. ++        int              src_pitch = ftbit->pitch;
  217. ++        int              width     = target->width;
  218. ++        int              height    = target->rows;
  219. ++        int              pitch     = target->pitch;
  220. ++        int              subpixel;
  221. ++        int              h;
  222. ++
  223. ++        subpixel = ( mode == FT_RENDER_MODE_LCD ||
  224. ++                     mode == FT_RENDER_MODE_LCD_V );
  225. ++
  226. ++        if ( src_pitch < 0 )
  227. ++          srcLine -= src_pitch*(ftbit->rows-1);
  228. ++
  229. ++        switch ( ftbit->pixel_mode )
  230. ++        {
  231. ++        case FT_PIXEL_MODE_MONO:
  232. ++            if ( subpixel )  /* convert mono to ARGB32 values */
  233. ++            {
  234. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  235. ++                {
  236. ++                    int  x;
  237. ++
  238. ++                    for ( x = 0; x < width; x++ )
  239. ++                    {
  240. ++                        if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
  241. ++                            ((unsigned int*)dstLine)[x] = 0xffffffffU;
  242. ++                    }
  243. ++                }
  244. ++            }
  245. ++            else if ( mode == FT_RENDER_MODE_NORMAL )  /* convert mono to 8-bit gray */
  246. ++            {
  247. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  248. ++                {
  249. ++                    int  x;
  250. ++
  251. ++                    for ( x = 0; x < width; x++ )
  252. ++                    {
  253. ++                        if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
  254. ++                            dstLine[x] = 0xff;
  255. ++                    }
  256. ++                }
  257. ++            }
  258. ++            else  /* copy mono to mono */
  259. ++            {
  260. ++                int  bytes = (width+7) >> 3;
  261. ++
  262. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  263. ++                    memcpy( dstLine, srcLine, bytes );
  264. ++            }
  265. ++            break;
  266. ++
  267. ++        case FT_PIXEL_MODE_GRAY:
  268. ++            if ( subpixel )  /* convert gray to ARGB32 values */
  269. ++            {
  270. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  271. ++                {
  272. ++                    int            x;
  273. ++                    unsigned int*  dst = (unsigned int*)dstLine;
  274. ++
  275. ++                    for ( x = 0; x < width; x++ )
  276. ++                    {
  277. ++                        unsigned int  pix = srcLine[x];
  278. ++
  279. ++                        pix |= (pix << 8);
  280. ++                        pix |= (pix << 16);
  281. ++
  282. ++                        dst[x] = pix;
  283. ++                    }
  284. ++                }
  285. ++            }
  286. ++            else  /* copy gray into gray */
  287. ++            {
  288. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  289. ++                    memcpy( dstLine, srcLine, width );
  290. ++            }
  291. ++            break;
  292. ++
  293. ++        case FT_PIXEL_MODE_LCD:
  294. ++            if ( !bgr )
  295. ++            {
  296. ++                /* convert horizontal RGB into ARGB32 */
  297. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  298. ++                {
  299. ++                    int            x;
  300. ++                    unsigned char* src = srcLine;
  301. ++                    unsigned int*  dst = (unsigned int*)dstLine;
  302. ++
  303. ++                    for ( x = 0; x < width; x++, src += 3 )
  304. ++                    {
  305. ++                        unsigned int  pix;
  306. ++
  307. ++                        pix = ((unsigned int)src[0] << 16) |
  308. ++                              ((unsigned int)src[1] <<  8) |
  309. ++                              ((unsigned int)src[2]      ) |
  310. ++                              ((unsigned int)src[1] << 24) ;
  311. ++
  312. ++                        dst[x] = pix;
  313. ++                    }
  314. ++                }
  315. ++            }
  316. ++            else
  317. ++            {
  318. ++                /* convert horizontal BGR into ARGB32 */
  319. ++                for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
  320. ++                {
  321. ++                    int            x;
  322. ++                    unsigned char* src = srcLine;
  323. ++                    unsigned int*  dst = (unsigned int*)dstLine;
  324. ++
  325. ++                    for ( x = 0; x < width; x++, src += 3 )
  326. ++                    {
  327. ++                        unsigned int  pix;
  328. ++
  329. ++                        pix = ((unsigned int)src[2] << 16) |
  330. ++                              ((unsigned int)src[1] <<  8) |
  331. ++                              ((unsigned int)src[0]      ) |
  332. ++                              ((unsigned int)src[1] << 24) ;
  333. ++
  334. ++                        dst[x] = pix;
  335. ++                    }
  336. ++                }
  337. ++            }
  338. ++            break;
  339. ++
  340. ++        default:  /* FT_PIXEL_MODE_LCD_V */
  341. ++            /* convert vertical RGB into ARGB32 */
  342. ++            if ( !bgr )
  343. ++            {
  344. ++                for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
  345. ++                {
  346. ++                    int            x;
  347. ++                    unsigned char* src = srcLine;
  348. ++                    unsigned int*  dst = (unsigned int*)dstLine;
  349. ++
  350. ++                    for ( x = 0; x < width; x++, src += 1 )
  351. ++                    {
  352. ++                        unsigned int  pix;
  353. ++
  354. ++                        pix = ((unsigned int)src[0]           << 16) |
  355. ++                              ((unsigned int)src[src_pitch]   <<  8) |
  356. ++                              ((unsigned int)src[src_pitch*2]      ) |
  357. ++                              ((unsigned int)src[src_pitch]   << 24) ;
  358. ++
  359. ++                        dst[x] = pix;
  360. ++                    }
  361. ++                }
  362. ++            }
  363. ++            else
  364. ++            {
  365. ++                for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
  366. ++                {
  367. ++                    int            x;
  368. ++                    unsigned char* src = srcLine;
  369. ++                    unsigned int*  dst = (unsigned int*)dstLine;
  370. ++
  371. ++                    for ( x = 0; x < width; x++, src += 1 )
  372. ++                    {
  373. ++                        unsigned int  pix;
  374. ++
  375. ++                        pix = ((unsigned int)src[src_pitch*2] << 16) |
  376. ++                              ((unsigned int)src[src_pitch]   <<  8) |
  377. ++                              ((unsigned int)src[0]                ) |
  378. ++                              ((unsigned int)src[src_pitch]   << 24) ;
  379. ++
  380. ++                        dst[x] = pix;
  381. ++                    }
  382. ++                }
  383. ++            }
  384. ++        }
  385. ++    }
  386. ++}
  387. ++
  388. ++
  389. + _X_EXPORT void
  390. + XftFontLoadGlyphs (Display        *dpy,
  391. +          XftFont      *pub,
  392. +@@ -87,20 +367,14 @@
  393. +     unsigned char   *bufBitmap = bufLocal;
  394. +     int           bufSize = sizeof (bufLocal);
  395. +     int           size, pitch;
  396. +-    unsigned char   bufLocalRgba[4096];
  397. +-    unsigned char   *bufBitmapRgba = bufLocalRgba;
  398. +-    int           bufSizeRgba = sizeof (bufLocalRgba);
  399. +-    int           sizergba, pitchrgba, widthrgba;
  400. +     int           width;
  401. +     int           height;
  402. +     int           left, right, top, bottom;
  403. +-    int           hmul = 1;
  404. +-    int           vmul = 1;
  405. +-    FT_Bitmap     ftbit;
  406. +-    FT_Matrix     matrix;
  407. ++    FT_Bitmap*        ftbit;
  408. ++    FT_Bitmap       local;
  409. +     FT_Vector     vector;
  410. +-    Bool      subpixel = False;
  411. +     FT_Face       face;
  412. ++    FT_Render_Mode  mode = FT_RENDER_MODE_MONO;
  413. +
  414. +     if (!info)
  415. +   return;
  416. +@@ -110,24 +384,19 @@
  417. +     if (!face)
  418. +   return;
  419. +
  420. +-    matrix.xx = matrix.yy = 0x10000L;
  421. +-    matrix.xy = matrix.yx = 0;
  422. +-
  423. +     if (font->info.antialias)
  424. +     {
  425. +   switch (font->info.rgba) {
  426. +   case FC_RGBA_RGB:
  427. +   case FC_RGBA_BGR:
  428. +-      matrix.xx *= 3;
  429. +-      subpixel = True;
  430. +-      hmul = 3;
  431. ++      mode = FT_RENDER_MODE_LCD;
  432. +       break;
  433. +   case FC_RGBA_VRGB:
  434. +   case FC_RGBA_VBGR:
  435. +-      matrix.yy *= 3;
  436. +-      vmul = 3;
  437. +-      subpixel = True;
  438. ++            mode = FT_RENDER_MODE_LCD_V;
  439. +       break;
  440. ++        default:
  441. ++            mode = FT_RENDER_MODE_NORMAL;
  442. +   }
  443. +     }
  444. +
  445. +@@ -148,7 +417,10 @@
  446. +   if (xftg->glyph_memory)
  447. +       continue;
  448. +  
  449. ++        FT_Library_SetLcdFilter( _XftFTlibrary, font->info.lcd_filter);
  450. ++
  451. +   error = FT_Load_Glyph (face, glyphindex, font->info.load_flags);
  452. ++
  453. +   if (error)
  454. +   {
  455. +       /*
  456. +@@ -181,7 +453,7 @@
  457. +   /*
  458. +    * Compute glyph metrics from FreeType information
  459. +    */
  460. +-  if(font->info.transform && glyphslot->format != ft_glyph_format_bitmap)
  461. ++  if(font->info.transform && glyphslot->format != FT_GLYPH_FORMAT_BITMAP)
  462. +   {
  463. +       /*
  464. +        * calculate the true width by transforming all four corners.
  465. +@@ -260,17 +532,14 @@
  466. +       }
  467. +   }
  468. +
  469. +-  if (font->info.antialias)
  470. +-      pitch = (width * hmul + 3) & ~3;
  471. +-  else
  472. +-      pitch = ((width + 31) & ~31) >> 3;
  473. +-
  474. +-  size = pitch * height * vmul;
  475. ++        if ( glyphslot->format != FT_GLYPH_FORMAT_BITMAP )
  476. ++        {
  477. ++            error = FT_Render_Glyph( face->glyph, mode );
  478. ++            if (error)
  479. ++                continue;
  480. ++        }
  481. +
  482. +-  xftg->metrics.width = width;
  483. +-  xftg->metrics.height = height;
  484. +-  xftg->metrics.x = -TRUNC(left);
  485. +-  xftg->metrics.y = TRUNC(top);
  486. ++        FT_Library_SetLcdFilter( _XftFTlibrary, FT_LCD_FILTER_NONE );
  487. +
  488. +   if (font->info.spacing >= FC_MONO)
  489. +   {
  490. +@@ -310,103 +579,13 @@
  491. +       xftg->metrics.yOff = -TRUNC(ROUND(glyphslot->advance.y));
  492. +   }
  493. +  
  494. +-  /*
  495. +-   * If the glyph is relatively large (> 1% of server memory),
  496. +-   * don't send it until necessary
  497. +-   */
  498. +-  if (!need_bitmaps && size > info->max_glyph_memory / 100)
  499. +-      continue;
  500. +  
  501. +-  /*
  502. +-   * Make sure there's enough buffer space for the glyph
  503. +-   */
  504. +-  if (size > bufSize)
  505. +-  {
  506. +-      if (bufBitmap != bufLocal)
  507. +-      free (bufBitmap);
  508. +-      bufBitmap = (unsigned char *) malloc (size);
  509. +-      if (!bufBitmap)
  510. +-      continue;
  511. +-      bufSize = size;
  512. +-  }
  513. +-  memset (bufBitmap, 0, size);
  514. +-
  515. +-  /*
  516. +-   * Rasterize into the local buffer
  517. +-   */
  518. +-  switch (glyphslot->format) {
  519. +-  case ft_glyph_format_outline:
  520. +-      ftbit.width      = width * hmul;
  521. +-      ftbit.rows       = height * vmul;
  522. +-      ftbit.pitch      = pitch;
  523. +-      if (font->info.antialias)
  524. +-      ftbit.pixel_mode = ft_pixel_mode_grays;
  525. +-      else
  526. +-      ftbit.pixel_mode = ft_pixel_mode_mono;
  527. +-     
  528. +-      ftbit.buffer     = bufBitmap;
  529. +-     
  530. +-      if (subpixel)
  531. +-      FT_Outline_Transform (&glyphslot->outline, &matrix);
  532. ++        // compute the size of the final bitmap
  533. ++        ftbit  = &glyphslot->bitmap;
  534. +
  535. +-      FT_Outline_Translate ( &glyphslot->outline, -left*hmul, -bottom*vmul );
  536. +-
  537. +-      FT_Outline_Get_Bitmap( _XftFTlibrary, &glyphslot->outline, &ftbit );
  538. +-      break;
  539. +-  case ft_glyph_format_bitmap:
  540. +-      if (font->info.antialias)
  541. +-      {
  542. +-      unsigned char   *srcLine, *dstLine;
  543. +-      int     height;
  544. +-      int     x;
  545. +-      int     h, v;
  546. +-
  547. +-      srcLine = glyphslot->bitmap.buffer;
  548. +-      dstLine = bufBitmap;
  549. +-      height = glyphslot->bitmap.rows;
  550. +-      while (height--)
  551. +-      {
  552. +-          for (x = 0; x < glyphslot->bitmap.width; x++)
  553. +-          {
  554. +-          /* always MSB bitmaps */
  555. +-          unsigned char   a = ((srcLine[x >> 3] & (0x80 >> (x & 7))) ?
  556. +-                       0xff : 0x00);
  557. +-          if (subpixel)
  558. +-          {
  559. +-              for (v = 0; v < vmul; v++)
  560. +-              for (h = 0; h < hmul; h++)
  561. +-                  dstLine[v * pitch + x*hmul + h] = a;
  562. +-          }
  563. +-          else
  564. +-              dstLine[x] = a;
  565. +-          }
  566. +-          dstLine += pitch * vmul;
  567. +-          srcLine += glyphslot->bitmap.pitch;
  568. +-      }
  569. +-      }
  570. +-      else
  571. +-      {
  572. +-      unsigned char   *srcLine, *dstLine;
  573. +-      int     h, bytes;
  574. +-
  575. +-      srcLine = glyphslot->bitmap.buffer;
  576. +-      dstLine = bufBitmap;
  577. +-      h = glyphslot->bitmap.rows;
  578. +-      bytes = (glyphslot->bitmap.width + 7) >> 3;
  579. +-      while (h--)
  580. +-      {
  581. +-          memcpy (dstLine, srcLine, bytes);
  582. +-          dstLine += pitch;
  583. +-          srcLine += glyphslot->bitmap.pitch;
  584. +-      }
  585. +-      }
  586. +-      break;
  587. +-  default:
  588. +-      if (XftDebug() & XFT_DBG_GLYPH)
  589. +-      printf ("glyph %d is not in a usable format\n",
  590. +-          (int) glyphindex);
  591. +-      continue;
  592. +-  }
  593. ++        width  = ftbit->width;
  594. ++        height = ftbit->rows;
  595. ++        pitch  = (width+3) & ~3;
  596. +  
  597. +   if (XftDebug() & XFT_DBG_GLYPH)
  598. +   {
  599. +@@ -423,29 +602,72 @@
  600. +       int     x, y;
  601. +       unsigned char   *line;
  602. +
  603. +-      line = bufBitmap;
  604. +-      for (y = 0; y < height * vmul; y++)
  605. ++                line = ftbit->buffer;
  606. ++
  607. ++                if (ftbit->pitch < 0)
  608. ++                  line -= ftbit->pitch*(height-1);
  609. ++
  610. ++                for (y = 0; y < height; y++)
  611. +       {
  612. +           if (font->info.antialias)
  613. +           {
  614. +-          static char    den[] = { " .:;=+*#" };
  615. +-          for (x = 0; x < pitch; x++)
  616. ++                        static const char    den[] = { " .:;=+*#" };
  617. ++                        for (x = 0; x < width; x++)
  618. +               printf ("%c", den[line[x] >> 5]);
  619. +           }
  620. +           else
  621. +           {
  622. +-          for (x = 0; x < pitch * 8; x++)
  623. ++                        for (x = 0; x < width * 8; x++)
  624. +           {
  625. +               printf ("%c", line[x>>3] & (1 << (x & 7)) ? '#' : ' ');
  626. +           }
  627. +           }
  628. +           printf ("|\n");
  629. +-          line += pitch;
  630. ++                    line += ftbit->pitch;
  631. +       }
  632. +       printf ("\n");
  633. +       }
  634. +   }
  635. +
  636. ++        size = _compute_xrender_bitmap_size( &local, glyphslot, mode );
  637. ++        if ( size < 0 )
  638. ++            continue;
  639. ++
  640. ++        xftg->metrics.width  = local.width;
  641. ++  xftg->metrics.height = local.rows;
  642. ++  xftg->metrics.x      = - glyphslot->bitmap_left;
  643. ++  xftg->metrics.y      =   glyphslot->bitmap_top;
  644. ++     
  645. ++      /*
  646. ++   * If the glyph is relatively large (> 1% of server memory),
  647. ++   * don't send it until necessary
  648. ++       */
  649. ++  if (!need_bitmaps && size > info->max_glyph_memory / 100)
  650. ++      continue;
  651. ++
  652. ++  /*
  653. ++   * Make sure there's enough buffer space for the glyph
  654. ++   */
  655. ++  if (size > bufSize)
  656. ++      {
  657. ++      if (bufBitmap != bufLocal)
  658. ++      free (bufBitmap);
  659. ++      bufBitmap = (unsigned char *) malloc (size);
  660. ++      if (!bufBitmap)
  661. ++          continue;
  662. ++      bufSize = size;
  663. ++      }
  664. ++  memset (bufBitmap, 0, size);
  665. ++
  666. ++        local.buffer = bufBitmap;
  667. ++     
  668. ++        _fill_xrender_bitmap( &local, glyphslot, mode,
  669. ++                              (font->info.rgba == FC_RGBA_BGR  ||
  670. ++                               font->info.rgba == FC_RGBA_VBGR ) );
  671. ++  /*
  672. ++   * Copy or convert into local buffer
  673. ++   */
  674. ++
  675. +   /*
  676. +    * Use the glyph index as the wire encoding; it
  677. +    * might be more efficient for some locales to map
  678. +@@ -455,121 +677,23 @@
  679. +    */
  680. +   glyph = (Glyph) glyphindex;
  681. +
  682. +-  if (subpixel)
  683. +-  {
  684. +-      int         x, y;
  685. +-      unsigned char   *in_line, *out_line, *in;
  686. +-      unsigned int    *out;
  687. +-      unsigned int    red, green, blue;
  688. +-      int         rf, gf, bf;
  689. +-      int         s;
  690. +-      int         o, os;
  691. +-     
  692. +-      /*
  693. +-       * Filter the glyph to soften the color fringes
  694. +-       */
  695. +-      widthrgba = width;
  696. +-      pitchrgba = (widthrgba * 4 + 3) & ~3;
  697. +-      sizergba = pitchrgba * height;
  698. +-
  699. +-      os = 1;
  700. +-      switch (font->info.rgba) {
  701. +-      case FC_RGBA_VRGB:
  702. +-      os = pitch;
  703. +-      case FC_RGBA_RGB:
  704. +-      default:
  705. +-      rf = 0;
  706. +-      gf = 1;
  707. +-      bf = 2;
  708. +-      break;
  709. +-      case FC_RGBA_VBGR:
  710. +-      os = pitch;
  711. +-      case FC_RGBA_BGR:
  712. +-      bf = 0;
  713. +-      gf = 1;
  714. +-      rf = 2;
  715. +-      break;
  716. +-      }
  717. +-      if (sizergba > bufSizeRgba)
  718. +-      {
  719. +-      if (bufBitmapRgba != bufLocalRgba)
  720. +-          free (bufBitmapRgba);
  721. +-      bufBitmapRgba = (unsigned char *) malloc (sizergba);
  722. +-      if (!bufBitmapRgba)
  723. +-          continue;
  724. +-      bufSizeRgba = sizergba;
  725. +-      }
  726. +-      memset (bufBitmapRgba, 0, sizergba);
  727. +-      in_line = bufBitmap;
  728. +-      out_line = bufBitmapRgba;
  729. +-      for (y = 0; y < height; y++)
  730. +-      {
  731. +-      in = in_line;
  732. +-      out = (unsigned int *) out_line;
  733. +-      in_line += pitch * vmul;
  734. +-      out_line += pitchrgba;
  735. +-      for (x = 0; x < width * hmul; x += hmul)
  736. +-      {
  737. +-          red = green = blue = 0;
  738. +-          o = 0;
  739. +-          for (s = 0; s < 3; s++)
  740. +-          {
  741. +-          red += filters[rf][s]*in[x+o];
  742. +-          green += filters[gf][s]*in[x+o];
  743. +-          blue += filters[bf][s]*in[x+o];
  744. +-          o += os;
  745. +-          }
  746. +-          red = red / 65536;
  747. +-          green = green / 65536;
  748. +-          blue = blue / 65536;
  749. +-          *out++ = (green << 24) | (red << 16) | (green << 8) | blue;
  750. +-      }
  751. +-      }
  752. +-     
  753. +-      xftg->glyph_memory = sizergba + sizeof (XftGlyph);
  754. +-      if (font->format)
  755. ++  xftg->glyph_memory = size + sizeof (XftGlyph);
  756. ++      if (font->format)
  757. +       {
  758. +       if (!font->glyphset)
  759. +           font->glyphset = XRenderCreateGlyphSet (dpy, font->format);
  760. +-      if (ImageByteOrder (dpy) != XftNativeByteOrder ())
  761. +-          XftSwapCARD32 ((CARD32 *) bufBitmapRgba, sizergba >> 2);
  762. +-      XRenderAddGlyphs (dpy, font->glyphset, &glyph,
  763. +-                &xftg->metrics, 1,
  764. +-                (char *) bufBitmapRgba, sizergba);
  765. +-      }
  766. +-      else
  767. +-      {
  768. +-      if (sizergba)
  769. +-      {
  770. +-          xftg->bitmap = malloc (sizergba);
  771. +-          if (xftg->bitmap)
  772. +-          memcpy (xftg->bitmap, bufBitmapRgba, sizergba);
  773. +-      }
  774. +-      else
  775. +-          xftg->bitmap = NULL;
  776. +-      }
  777. +-  }
  778. +-  else
  779. +-  {
  780. +-      xftg->glyph_memory = size + sizeof (XftGlyph);
  781. +-      if (font->format)
  782. +-      {
  783. +-      /*
  784. +-       * swap bit order around; FreeType is always MSBFirst
  785. +-       */
  786. +-      if (!font->info.antialias)
  787. ++      if ( mode == FT_RENDER_MODE_MONO )
  788. +       {
  789. ++        /* swap bits in each byte */
  790. +           if (BitmapBitOrder (dpy) != MSBFirst)
  791. +           {
  792. +-          unsigned char   *line;
  793. +-          unsigned char   c;
  794. +-          int         i;
  795. ++            unsigned char   *line = (unsigned char*)bufBitmap;
  796. ++            int             i = size;
  797. +
  798. +-          line = (unsigned char *) bufBitmap;
  799. +-          i = size;
  800. +           while (i--)
  801. +           {
  802. +-              c = *line;
  803. ++            int  c = *line;
  804. ++
  805. +               c = ((c << 1) & 0xaa) | ((c >> 1) & 0x55);
  806. +               c = ((c << 2) & 0xcc) | ((c >> 2) & 0x33);
  807. +               c = ((c << 4) & 0xf0) | ((c >> 4) & 0x0f);
  808. +@@ -577,8 +701,12 @@
  809. +           }
  810. +           }
  811. +       }
  812. +-      if (!font->glyphset)
  813. +-          font->glyphset = XRenderCreateGlyphSet (dpy, font->format);
  814. ++            else if ( mode != FT_RENDER_MODE_NORMAL )
  815. ++            {
  816. ++                /* invert ARGB <=> BGRA */
  817. ++                if (ImageByteOrder (dpy) != XftNativeByteOrder ())
  818. ++                    XftSwapCARD32 ((CARD32 *) bufBitmap, size >> 2);
  819. ++            }
  820. +       XRenderAddGlyphs (dpy, font->glyphset, &glyph,
  821. +                 &xftg->metrics, 1,
  822. +                 (char *) bufBitmap, size);
  823. +@@ -594,7 +722,7 @@
  824. +       else
  825. +           xftg->bitmap = NULL;
  826. +       }
  827. +-  }
  828. ++
  829. +   font->glyph_memory += xftg->glyph_memory;
  830. +   info->glyph_memory += xftg->glyph_memory;
  831. +   if (XftDebug() & XFT_DBG_CACHE)
  832. +@@ -605,8 +733,6 @@
  833. +     }
  834. +     if (bufBitmap != bufLocal)
  835. +   free (bufBitmap);
  836. +-    if (bufBitmapRgba != bufLocalRgba)
  837. +-  free (bufBitmapRgba);
  838. +     XftUnlockFace (&font->public);
  839. + }
  840. +
  841. +--- src/xftint.h
  842. ++++ src/xftint.h
  843. +@@ -145,6 +145,7 @@
  844. +     FcBool        antialias;  /* doing antialiasing */
  845. +     FcBool        embolden;   /* force emboldening */
  846. +     int           rgba;       /* subpixel order */
  847. ++    int           lcd_filter; /* lcd filter */
  848. +     FT_Matrix     matrix;     /* glyph transformation matrix */
  849. +     FcBool        transform;  /* non-identify matrix? */
  850. +     FT_Int        load_flags; /* glyph load flags */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement