2019-03-05 18:28:12 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2019-03-05 18:28:12 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-03-05 18:28:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CRYOMNI3D_FONT_MANAGER_H
|
|
|
|
#define CRYOMNI3D_FONT_MANAGER_H
|
|
|
|
|
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/str.h"
|
2019-11-16 20:22:45 +00:00
|
|
|
#include "common/str-enc.h"
|
|
|
|
#include "common/ustr.h"
|
2019-03-05 18:28:12 +00:00
|
|
|
#include "common/rect.h"
|
|
|
|
|
2019-11-16 20:22:45 +00:00
|
|
|
#include "graphics/font.h"
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
namespace Graphics {
|
|
|
|
class ManagedSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace CryOmni3D {
|
|
|
|
|
|
|
|
class FontManager {
|
|
|
|
public:
|
|
|
|
FontManager();
|
|
|
|
virtual ~FontManager();
|
|
|
|
|
2023-02-26 17:32:55 +00:00
|
|
|
void loadFonts(const Common::Array<Common::Path> &fontFiles, Common::CodePage codepage);
|
|
|
|
void loadTTFList(const Common::Path &listFile, Common::CodePage codepage);
|
2019-03-05 18:28:12 +00:00
|
|
|
void setCurrentFont(int currentFont);
|
2019-05-26 16:29:57 +00:00
|
|
|
uint getCurrentFont() { return _currentFontId; }
|
2019-03-05 18:28:12 +00:00
|
|
|
void setTransparentBackground(bool transparent) { _transparentBackground = transparent; }
|
2019-05-26 16:29:57 +00:00
|
|
|
void setSpaceWidth(uint additionalSpace);
|
2019-03-05 18:28:12 +00:00
|
|
|
void setForeColor(byte color) { _foreColor = color; }
|
|
|
|
void setLineHeight(int h) { _lineHeight = h; }
|
|
|
|
int lineHeight() { return _lineHeight; }
|
2019-05-26 16:29:57 +00:00
|
|
|
void setCharSpacing(uint w) { _charSpacing = w; }
|
2019-03-05 18:28:12 +00:00
|
|
|
void setSurface(Graphics::ManagedSurface *surface) { _currentSurface = surface; }
|
|
|
|
|
2019-11-16 20:22:45 +00:00
|
|
|
int getFontMaxHeight() { return _currentFont->getFontHeight(); }
|
|
|
|
|
|
|
|
void displayInt(uint x, uint y, int value) const {
|
|
|
|
displayStr_(x, y,
|
|
|
|
toU32(Common::String::format("%d", value)));
|
|
|
|
}
|
|
|
|
void displayStr(uint x, uint y, const Common::String &text) const { displayStr_(x, y, toU32(text)); }
|
2020-11-30 12:29:45 +00:00
|
|
|
void displayStr(uint x, uint y, const Common::U32String &text) const { displayStr_(x, y, text); }
|
2019-11-16 20:22:45 +00:00
|
|
|
uint getStrWidth(const Common::String &text) const { return getStrWidth(toU32(text)); }
|
2020-11-30 12:29:45 +00:00
|
|
|
uint getStrWidth(const Common::U32String &text) const;
|
2019-11-16 20:22:45 +00:00
|
|
|
|
|
|
|
uint getLinesCount(const Common::String &text, uint width) { return getLinesCount(toU32(text), width); }
|
|
|
|
|
|
|
|
void setupBlock(const Common::Rect &block, bool justifyText = false) {
|
|
|
|
_blockRect = block;
|
|
|
|
_blockPos.x = block.left;
|
|
|
|
_blockPos.y = block.top;
|
|
|
|
_justifyText = justifyText;
|
|
|
|
}
|
|
|
|
bool displayBlockText(const Common::String &text) {
|
|
|
|
_blockTextStr = toU32(text);
|
|
|
|
return displayBlockText(_blockTextStr, _blockTextStr.begin());
|
|
|
|
}
|
|
|
|
bool displayBlockTextContinue() { return displayBlockText(_blockTextStr, _blockTextRemaining); }
|
2019-03-05 18:28:12 +00:00
|
|
|
Common::Point blockTextLastPos() { return _blockPos; }
|
|
|
|
|
|
|
|
private:
|
2020-11-30 12:29:45 +00:00
|
|
|
Common::U32String toU32(const Common::String &text) const;
|
2019-11-16 20:22:45 +00:00
|
|
|
|
2020-11-30 12:29:45 +00:00
|
|
|
uint displayStr_(uint x, uint y, const Common::U32String &text) const;
|
|
|
|
uint getLinesCount(const Common::U32String &text, uint width);
|
|
|
|
bool displayBlockText(const Common::U32String &text, Common::U32String::const_iterator begin);
|
|
|
|
void calculateWordWrap(const Common::U32String &text, Common::U32String::const_iterator *position,
|
|
|
|
uint *finalPos, bool *has_br, Common::Array<Common::U32String> &words) const;
|
2019-11-16 20:22:45 +00:00
|
|
|
|
|
|
|
Common::CodePage _codepage;
|
|
|
|
bool _toUnicode;
|
|
|
|
Common::Array<Graphics::Font *> _fonts;
|
|
|
|
const Graphics::Font *_currentFont;
|
2019-05-26 16:29:57 +00:00
|
|
|
uint _currentFontId;
|
2019-03-05 18:28:12 +00:00
|
|
|
bool _transparentBackground;
|
2019-05-26 16:29:57 +00:00
|
|
|
uint _spaceWidth;
|
|
|
|
uint _charSpacing;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
byte _foreColor;
|
|
|
|
|
|
|
|
Graphics::ManagedSurface *_currentSurface;
|
|
|
|
|
|
|
|
Common::Rect _blockRect;
|
|
|
|
Common::Point _blockPos;
|
|
|
|
int _lineHeight;
|
|
|
|
bool _justifyText;
|
2020-11-30 12:29:45 +00:00
|
|
|
Common::U32String _blockTextStr;
|
|
|
|
Common::U32String::const_iterator _blockTextRemaining;
|
2019-11-16 20:22:45 +00:00
|
|
|
|
|
|
|
// Specific parameters for non alphabetic languages
|
|
|
|
void setupWrapParameters();
|
|
|
|
bool _useSpaceDelimiter;
|
|
|
|
bool _keepASCIIjoined;
|
2019-03-05 18:28:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace CryOmni3D
|
|
|
|
|
|
|
|
#endif
|