1 /* 2 * text.h - adds text image support to beryl. 3 * Copyright: (C) 2006 Patrick Niklaus 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * 19 */ 20 21 #ifndef _COMPIZ_TEXT_H 22 #define _COMPIZ_TEXT_H 23 24 #define TEXT_ABIVERSION 20090103 25 26 /** 27 * Flags to be passed into the flags field of CompTextAttrib 28 */ 29 #define CompTextFlagStyleBold (1 << 0) /**< render the text in bold */ 30 #define CompTextFlagStyleItalic (1 << 1) /**< render the text italic */ 31 #define CompTextFlagEllipsized (1 << 2) /**< ellipsize the text if the 32 specified maximum size is too 33 small */ 34 #define CompTextFlagWithBackground (1 << 3) /**< render a rounded rectangle as 35 background behind the text */ 36 #define CompTextFlagNoAutoBinding (1 << 4) /**< do not automatically bind the 37 rendered text pixmap to a 38 texture */ 39 40 /** 41 * Input data structure that specifies how the text is to be rendered 42 */ 43 typedef struct _CompTextAttrib { 44 char *family; /**< font family */ 45 int size; /**< font size in points */ 46 unsigned short color[4]; /**< font color (RGBA) */ 47 48 unsigned int flags; /**< rendering flags, see above */ 49 50 int maxWidth; /**< maximum width of the generated pixmap */ 51 int maxHeight; /**< maximum height of the generated pixmap */ 52 53 int bgHMargin; /**< horizontal margin in pixels 54 (offset of text into background) */ 55 int bgVMargin; /**< vertical margin */ 56 unsigned short bgColor[4]; /**< background color (RGBA) */ 57 } CompTextAttrib; 58 59 /** 60 * Output data structure that represents the rendered text 61 */ 62 typedef struct _CompTextData { 63 CompTexture *texture; /**< texture the text pixmap is bound to */ 64 Pixmap pixmap; /**< text pixmap */ 65 unsigned int width; /**< pixmap width */ 66 unsigned int height; /**< pixmap height */ 67 } CompTextData; 68 69 /** 70 * Prototype of text-to-pixmap rendering function 71 * 72 * @param s screen the text is rendered on 73 * @param text text to be rendered in ASCII or UTF-8 encoding 74 * @param attrib text rendering attributes 75 * 76 * @return valid text data on success, NULL on failure 77 */ 78 typedef CompTextData * 79 (*RenderTextProc) (CompScreen *s, 80 const char *text, 81 const CompTextAttrib *attrib); 82 83 /** 84 * Prototype of window title-to-pixmap rendering function 85 * 86 * @param s screen the text is rendered on 87 * @param window XID of the window whose title should be rendered 88 * @param withViewportNumber also render the viewport number behind 89 * the window title 90 * @param attrib text rendering attributes 91 * 92 * @return valid text data on success, NULL on failure 93 */ 94 typedef CompTextData * 95 (*RenderWindowTitleProc) (CompScreen *s, 96 Window window, 97 Bool withViewportNumber, 98 const CompTextAttrib *attrib); 99 100 /** 101 * Prototype of function drawing text data on screen 102 * 103 * Should only be called for text data which was automatically bound 104 * to a texture. 105 * NOTE: assumes that x and y are specified in the coordinate system 106 * currently used by OpenGL. For being able to specify screen 107 * coordinates, the caller needs to generate a transformation matrix 108 * using transformToScreenSpace and load it prior to calling this 109 * function. 110 * 111 * @param s screen the text is rendered on 112 * @param data text data structure 113 * @param x x position in current OpenGL coordinates 114 * @param y y position in current OpenGL coordinates 115 * @param alpha opacity for the drawn text (0.0 - transparent, 1.0 - opaque) 116 */ 117 typedef void (*DrawTextProc) (CompScreen *s, 118 const CompTextData *data, 119 float x, 120 float y, 121 float alpha); 122 123 /** 124 * Prototype of text data cleanup function 125 * 126 * @param s screen the data was generated for 127 * @param data data structure 128 */ 129 typedef void (*FiniTextDataProc) (CompScreen *s, 130 CompTextData *data); 131 132 /** 133 * Function pointer set that provides access to the 134 * above defined functions. 135 */ 136 typedef struct _TextFunc { 137 RenderTextProc renderText; 138 RenderWindowTitleProc renderWindowTitle; 139 DrawTextProc drawText; 140 FiniTextDataProc finiTextData; 141 } TextFunc; 142 143 #endif 144