1 /* texfonts.c */
2 /*****************************************************************************/
3 /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
4 /*                                                                           */
5 /* AS                                                                        */
6 /*                                                                           */
7 /* TeX-->ASCII/HTML Converter: Font Stuff                                    */
8 /*                                                                           */
9 /*****************************************************************************/
10 
11 #include <stdlib.h>
12 
13 #include "datatypes.h"
14 #include "texfonts.h"
15 
16 /*--------------------------------------------------------------------------*/
17 
18 typedef struct sFontSave
19 {
20   struct sFontSave *pNext;
21   int FontFlags;
22   tFontSize FontSize;
23 } tFontSave, *tpFontSave;
24 
25 /*--------------------------------------------------------------------------*/
26 
27 int CurrFontFlags, FontNest;
28 tFontSize CurrFontSize;
29 tFontType CurrFontType;
30 
31 static tpFontSave pFontStack;
32 
33 /*!------------------------------------------------------------------------
34  * \fn     InitFont(void)
35  * \brief  initialize font state
36  * ------------------------------------------------------------------------ */
37 
InitFont(void)38 void InitFont(void)
39 {
40   pFontStack = NULL;
41   FontNest = 0;
42   CurrFontSize = FontNormalSize;
43   CurrFontType = FontStandard;
44   CurrFontFlags = 0;
45 }
46 
47 /*!------------------------------------------------------------------------
48  * \fn     SaveFont(void)
49  * \brief  push font size & flags to stack
50  * ------------------------------------------------------------------------ */
51 
SaveFont(void)52 void SaveFont(void)
53 {
54   tpFontSave pNewSave;
55 
56   pNewSave = (tpFontSave) malloc(sizeof(*pNewSave));
57   pNewSave->pNext = pFontStack;
58   pNewSave->FontSize = CurrFontSize;
59   pNewSave->FontFlags = CurrFontFlags;
60   pFontStack = pNewSave;
61   FontNest++;
62 }
63 
64 /*!------------------------------------------------------------------------
65  * \fn     RestoreFont(void)
66  * \brief  push font size & flags to stack
67  * ------------------------------------------------------------------------ */
68 
69 extern void PrFontDiff(int OldFlags, int NewFlags);
70 extern void PrFontSize(tFontSize Type, Boolean On);
71 
RestoreFont(void)72 void RestoreFont(void)
73 {
74   tpFontSave pOldSave;
75 
76   if (!pFontStack)
77     return;
78 
79   PrFontDiff(CurrFontFlags, pFontStack->FontFlags);
80   PrFontSize(CurrFontSize, False);
81 
82   pOldSave = pFontStack;
83   pFontStack = pFontStack->pNext;
84   CurrFontSize = pOldSave->FontSize;
85   CurrFontFlags = pOldSave->FontFlags;
86   free(pOldSave);
87   FontNest--;
88 }
89 
90 /*!------------------------------------------------------------------------
91  * \fn     FreeFontStack(void)
92  * \brief  dispose pushed font settings
93  * ------------------------------------------------------------------------ */
94 
FreeFontStack(void)95 void FreeFontStack(void)
96 {
97   while (pFontStack)
98   {
99     tpFontSave pOld = pFontStack;
100     pFontStack = pOld->pNext;
101     free(pOld);
102   }
103 }
104