1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * Additional copyright for this file: 8 * Copyright (C) 1994-1998 Revolution Software Ltd. 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 2 13 * of the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 */ 24 25 #ifndef SWORD2_MAKETEXT_H 26 #define SWORD2_MAKETEXT_H 27 28 #include "sword2/debug.h" 29 30 namespace Sword2 { 31 32 // Output color for character border - should be be black but note that we 33 // have to use a different pen number during sequences 34 35 #define BORDER_PEN 194 36 37 // Usually the only texts on screen are the subtitles and the mouse-over text, 38 // but there can also be a considerable number of debugging messages... 39 40 #define MAX_text_blocs MAX_DEBUG_TEXTS + 1 41 42 enum { 43 // Doesn't keep the text inside the screen - only for debug text! 44 NO_JUSTIFICATION = 0, 45 46 // These all force text inside the screen edge margin when necessary 47 POSITION_AT_CENTER_OF_BASE = 1, 48 POSITION_AT_CENTER_OF_TOP = 2, 49 POSITION_AT_LEFT_OF_TOP = 3, 50 POSITION_AT_RIGHT_OF_TOP = 4, 51 POSITION_AT_LEFT_OF_BASE = 5, 52 POSITION_AT_RIGHT_OF_BASE = 6, 53 POSITION_AT_LEFT_OF_CENTER = 7, 54 POSITION_AT_RIGHT_OF_CENTER = 8 55 }; 56 57 enum { 58 DEFAULT_TEXT = 0, 59 FINNISH_TEXT = 1, 60 POLISH_TEXT = 2 61 }; 62 63 // Info about the text, used to create the SpriteInfo struct 64 65 struct TextBloc { 66 int16 x; 67 int16 y; 68 uint16 type; 69 byte *text_mem; 70 }; 71 72 // Info for each line of words in the output text sprite 73 74 struct LineInfo { 75 uint16 width; // Width in pixels 76 uint16 length; // Length in characters 77 }; 78 79 class FontRenderer { 80 private: 81 Sword2Engine *_vm; 82 TextBloc _blocList[MAX_text_blocs]; 83 84 // Layout variables - these used to be defines, but now we're dealing 85 // with three character sets 86 87 int8 _lineSpacing; // no. of pixels to separate lines of 88 // characters in the output sprite - negative 89 // for overlap 90 int8 _charSpacing; // no. of pixels to separate characters along 91 // each line - negative for overlap 92 uint8 _borderPen; // output pen color of character borders 93 94 uint16 analyzeSentence(const byte *sentence, uint16 maxWidth, uint32 fontRes, LineInfo *line); 95 byte *buildTextSprite(const byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines); 96 uint16 charWidth(byte ch, uint32 fontRes); 97 uint16 charHeight(uint32 fontRes); 98 byte *findChar(byte ch, byte *charSet); 99 void copyChar(byte *charPtr, byte *spritePtr, uint16 spriteWidth, uint8 pen); 100 101 public: FontRenderer(Sword2Engine * vm)102 FontRenderer(Sword2Engine *vm) : _vm(vm) { 103 for (int i = 0; i < MAX_text_blocs; i++) 104 _blocList[i].text_mem = NULL; 105 } 106 ~FontRenderer()107 ~FontRenderer() { 108 for (int i = 0; i < MAX_text_blocs; i++) 109 free(_blocList[i].text_mem); 110 } 111 112 byte *makeTextSprite(const byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border = BORDER_PEN); 113 114 void killTextBloc(uint32 bloc_number); 115 void printTextBlocs(); 116 117 uint32 buildNewBloc(byte *ascii, int16 x, int16 y, uint16 width, uint8 pen, uint32 type, uint32 fontRes, uint8 justification); 118 }; 119 120 } // End of namespace Sword2 121 122 #endif 123