home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / common / ibmFntUtil.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  9KB  |  360 lines

  1. /*
  2.  * $Id: ibmFntUtil.c,v 1.1 1991/09/20 18:24:03 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that 
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25.  
  26. #include "X.h"
  27. #include "Xmd.h"
  28. #include "Xproto.h"
  29. #include "dixfontstr.h"
  30. #include "fontstruct.h"
  31.  
  32. #include "OScompiler.h"
  33.  
  34. void
  35. GetGlyphsAndChars(font, count, chars, fontEncoding, 
  36.                 glyphcount, glyphs, indices)
  37.     FontPtr font;
  38.     unsigned long count;
  39.     register unsigned char *chars;
  40.     FontEncoding fontEncoding;
  41.     unsigned long *glyphcount;    /* RETURN */
  42.     CharInfoPtr glyphs[];    /* RETURN */
  43.     CARD16    indices[];    /* RETURN */
  44. {
  45.     CharInfoPtr        pCI = font->pCI;
  46.     FontInfoPtr        pFI = font->pFI;
  47.     unsigned int    firstCol = pFI->firstCol;
  48.     unsigned int    numCols = pFI->lastCol - firstCol + 1;
  49.     unsigned int    firstRow = pFI->firstRow;
  50.     unsigned int    numRows = pFI->lastRow - firstRow + 1;
  51.     unsigned int    chDefault = pFI->chDefault;
  52.     unsigned int    cDef = chDefault - firstCol;
  53.     register unsigned long    i;
  54.     unsigned long        n;
  55.     register unsigned int    c;
  56.     register CharInfoPtr    ci;
  57.  
  58.     n = 0;
  59.     switch (fontEncoding) {
  60.  
  61.     case Linear8Bit:
  62.     case TwoD8Bit:
  63.         if (pFI->allExist && (cDef < numCols)) {
  64.         for (i=0; i < count; i++) {
  65.  
  66.             c = (*chars++) - firstCol;
  67.             if (c >= numCols) {
  68.             c = cDef;
  69.             }
  70.             ci = &pCI[c];
  71.             indices[i] = c;
  72.             glyphs[i] = ci;
  73.         }
  74.         n = count;
  75.         } else {
  76.         for (i=0; i < count; i++) {
  77.     
  78.             c = (*chars++) - firstCol;
  79.             if (c < numCols) {
  80.             ci = &pCI[c];
  81.             if (ci->exists) {
  82.                 indices[n] = c;
  83.                 glyphs[n++] = ci; 
  84.                 continue;
  85.             }
  86.             }
  87.     
  88.             if (cDef < numCols) {
  89.             ci = &pCI[cDef];
  90.             if (ci->exists) {
  91.                 indices[n] = cDef;
  92.                 glyphs[n++] = ci;
  93.             }
  94.             }
  95.         }
  96.         }
  97.         break;
  98.  
  99.     case Linear16Bit:
  100.         if (pFI->allExist && (cDef < numCols)) {
  101.         for (i=0; i < count; i++) {
  102.  
  103.             c = *chars++ << 8;
  104.             c = (c | *chars++) - firstCol;
  105.             if (c >= numCols) {
  106.             c = cDef;
  107.             }
  108.             ci = &pCI[c];
  109.             indices[i] = c;
  110.             glyphs[i] = ci;
  111.         }
  112.         n = count;
  113.         } else {
  114.         for (i=0; i < count; i++) {
  115.     
  116.             c = *chars++ << 8;
  117.             c = (c | *chars++) - firstCol;
  118.             if (c < numCols) {
  119.             ci = &pCI[c];
  120.             if (ci->exists) {
  121.                 indices[n] = c;
  122.                 glyphs[n++] = ci; 
  123.                 continue;
  124.             }
  125.             }
  126.     
  127.             if (cDef < numCols) {
  128.             ci = &pCI[cDef];
  129.             if (ci->exists)  {
  130.                 indices[n] = cDef;
  131.                 glyphs[n++] = ci;
  132.             }
  133.             }
  134.         }
  135.         }
  136.         break;
  137.  
  138.     case TwoD16Bit:
  139.         for (i=0; i < count; i++) {
  140.         register unsigned int row;
  141.         register unsigned int col;
  142.  
  143.         row = (*chars++) - firstRow;
  144.         col = (*chars++) - firstCol;
  145.         if ((row < numRows) && (col < numCols)) {
  146.             c = row*numCols + col;
  147.             ci = &pCI[c];
  148.             if (ci->exists) {
  149.             indices[n] = c;
  150.             glyphs[n++] = ci; 
  151.             continue;
  152.             }
  153.         }
  154.  
  155.         row = (chDefault >> 8)-firstRow;
  156.         col = (chDefault & 0xff)-firstCol;
  157.         if ((row < numRows) && (col < numCols)) {
  158.             c = row*numCols + col;
  159.             ci = &pCI[c];
  160.             if (ci->exists) {
  161.             indices[n] = c;
  162.             glyphs[n++] = ci;
  163.             }
  164.         }
  165.         }
  166.         break;
  167.     }
  168.     *glyphcount = n;
  169.     return ;
  170. }
  171.  
  172. /***====================================================================***/
  173.  
  174. #define    CM_UNCHECKED    0
  175. #define    CM_VARIABLE    1
  176. #define    CM_CONSTANT    2
  177.  
  178. #define    CHECK_EXTENTS(f,ei,i,ci) \
  179.     if (ei==CM_VARIABLE) {\
  180.         (i)->overallAscent= MAX(    (i)->overallAscent,\
  181.                     (ci)->metrics.ascent);\
  182.         (i)->overallDescent= MAX(    (i)->overallDescent,\
  183.                     (ci)->metrics.descent);\
  184.         (i)->overallLeft=    MIN(    (i)->overallLeft,\
  185.             info->overallWidth+(ci)->metrics.leftSideBearing);\
  186.         (i)->overallRight=    MAX(    (i)->overallRight,\
  187.             info->overallWidth+(ci)->metrics.rightSideBearing);\
  188.         (i)->overallWidth+= (ci)->metrics.characterWidth;\
  189.     }\
  190.     else if (ei==CM_UNCHECKED) {\
  191.         (i)->overallAscent= (ci)->metrics.ascent;\
  192.         (i)->overallDescent= (ci)->metrics.descent;\
  193.         (i)->overallLeft=    (ci)->metrics.leftSideBearing;\
  194.         (i)->overallRight=    (ci)->metrics.rightSideBearing;\
  195.         (i)->overallWidth=    (ci)->metrics.characterWidth;\
  196.         if ((f)->pFI->constantMetrics)    ei= CM_CONSTANT;\
  197.         else                ei= CM_VARIABLE;\
  198.     }
  199.  
  200. void
  201. GetGlyphsCharsAndExtents(font, count, chars, fontEncoding, 
  202.                 glyphcount, glyphs, indices, info)
  203.     FontPtr font;
  204.     unsigned long count;
  205.     register unsigned char *chars;
  206.     FontEncoding fontEncoding;
  207.     unsigned long *glyphcount;    /* RETURN */
  208.     CharInfoPtr glyphs[];    /* RETURN */
  209.     CARD16    indices[];    /* RETURN */
  210.     ExtentInfoRec    *info;    /* RETURN */
  211. {
  212.     CharInfoPtr        pCI = font->pCI;
  213.     FontInfoPtr        pFI = font->pFI;
  214.     unsigned int    firstCol = pFI->firstCol;
  215.     unsigned int    numCols = pFI->lastCol - firstCol + 1;
  216.     unsigned int    firstRow = pFI->firstRow;
  217.     unsigned int    numRows = pFI->lastRow - firstRow + 1;
  218.     unsigned int    chDefault = pFI->chDefault;
  219.     unsigned int    cDef = chDefault - firstCol;
  220.     register unsigned long    i;
  221.     unsigned long        n;
  222.     register unsigned int    c;
  223.     register CharInfoPtr    ci;
  224.          int        extentType= CM_UNCHECKED;
  225.  
  226.     n = 0;
  227.     switch (fontEncoding) {
  228.  
  229.     case Linear8Bit:
  230.     case TwoD8Bit:
  231.         if (pFI->allExist && (cDef < numCols)) {
  232.         for (i=0; i < count; i++) {
  233.  
  234.             c = (*chars++) - firstCol;
  235.             if (c >= numCols) {
  236.             c = cDef;
  237.             }
  238.             ci = &pCI[c];
  239.             indices[i] = c;
  240.             glyphs[i] = ci;
  241.             CHECK_EXTENTS(font,extentType,info,ci);
  242.         }
  243.         n = count;
  244.         } else {
  245.         for (i=0; i < count; i++) {
  246.     
  247.             c = (*chars++) - firstCol;
  248.             if (c < numCols) {
  249.             ci = &pCI[c];
  250.             if (ci->exists) {
  251.                 indices[n] = c;
  252.                 glyphs[n++] = ci; 
  253.                 CHECK_EXTENTS(font,extentType,info,ci);
  254.                 continue;
  255.             }
  256.             }
  257.     
  258.             if (cDef < numCols) {
  259.             ci = &pCI[cDef];
  260.             if (ci->exists) {
  261.                 indices[n] = cDef;
  262.                 glyphs[n++] = ci;
  263.                 CHECK_EXTENTS(font,extentType,info,ci);
  264.             }
  265.             }
  266.         }
  267.         }
  268.         break;
  269.  
  270.     case Linear16Bit:
  271.         if (pFI->allExist && (cDef < numCols)) {
  272.         for (i=0; i < count; i++) {
  273.  
  274.             c = *chars++ << 8;
  275.             c = (c | *chars++) - firstCol;
  276.             if (c >= numCols) {
  277.             c = cDef;
  278.             }
  279.             ci = &pCI[c];
  280.             indices[i] = c;
  281.             glyphs[i] = ci;
  282.             CHECK_EXTENTS(font,extentType,info,ci);
  283.         }
  284.         n = count;
  285.         } else {
  286.         for (i=0; i < count; i++) {
  287.     
  288.             c = *chars++ << 8;
  289.             c = (c | *chars++) - firstCol;
  290.             if (c < numCols) {
  291.             ci = &pCI[c];
  292.             if (ci->exists) {
  293.                 indices[n] = c;
  294.                 glyphs[n++] = ci; 
  295.                 CHECK_EXTENTS(font,extentType,info,ci);
  296.                 continue;
  297.             }
  298.             }
  299.     
  300.             if (cDef < numCols) {
  301.             ci = &pCI[cDef];
  302.             if (ci->exists)  {
  303.                 indices[n] = cDef;
  304.                 glyphs[n++] = ci;
  305.                 CHECK_EXTENTS(font,extentType,info,ci);
  306.             }
  307.             }
  308.         }
  309.         }
  310.         break;
  311.  
  312.     case TwoD16Bit:
  313.         for (i=0; i < count; i++) {
  314.         register unsigned int row;
  315.         register unsigned int col;
  316.  
  317.         row = (*chars++) - firstRow;
  318.         col = (*chars++) - firstCol;
  319.         if ((row < numRows) && (col < numCols)) {
  320.             c = row*numCols + col;
  321.             ci = &pCI[c];
  322.             if (ci->exists) {
  323.             indices[n] = c;
  324.             glyphs[n++] = ci; 
  325.             CHECK_EXTENTS(font,extentType,info,ci);
  326.             continue;
  327.             }
  328.         }
  329.  
  330.         row = (chDefault >> 8)-firstRow;
  331.         col = (chDefault & 0xff)-firstCol;
  332.         if ((row < numRows) && (col < numCols)) {
  333.             c = row*numCols + col;
  334.             ci = &pCI[c];
  335.             if (ci->exists) {
  336.             indices[n] = c;
  337.             glyphs[n++] = ci;
  338.             CHECK_EXTENTS(font,extentType,info,ci);
  339.             }
  340.         }
  341.         }
  342.         break;
  343.     }
  344.  
  345.     info->drawDirection= font->pFI->drawDirection;
  346.     info->fontAscent= font->pFI->fontAscent;
  347.     info->fontDescent= font->pFI->fontDescent;
  348.     if (extentType==CM_UNCHECKED) {
  349.     info->overallAscent= info->overallDescent= 0;
  350.     info->overallLeft= info->overallRight= 0;
  351.     info->overallWidth= 0;
  352.     }
  353.     else if (extentType==CM_CONSTANT) {
  354.     info->overallRight += info->overallWidth * (count -1);
  355.     info->overallWidth *= count;
  356.     }
  357.     *glyphcount = n;
  358.     return ;
  359. }
  360.