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  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23  //=============================================================================
24  //
25  // This unit provides functions for reading compiled translation file.
26  //
27  //=============================================================================
28 
29 #ifndef AGS_SHARED_GAME_TRA_FILE_H
30 #define AGS_SHARED_GAME_TRA_FILE_H
31 
32 #include "ags/shared/util/error.h"
33 #include "ags/shared/util/stream.h"
34 #include "ags/shared/util/string_types.h"
35 
36 namespace AGS3 {
37 namespace AGS {
38 namespace Shared {
39 
40 enum TraFileErrorType {
41 	kTraFileErr_NoError,
42 	kTraFileErr_SignatureFailed,
43 	kTraFileErr_FormatNotSupported,
44 	kTraFileErr_GameIDMismatch,
45 	kTraFileErr_UnexpectedEOF,
46 	kTraFileErr_UnknownBlockType,
47 	kTraFileErr_BlockDataOverlapping,
48 };
49 
50 enum TraFileBlock {
51 	kTraFblk_ExtStrID = 0,
52 	kTraFblk_Dict = 1,
53 	kTraFblk_GameID = 2,
54 	kTraFblk_TextOpts = 3,
55 	// End of data tag
56 	kTraFile_EOF = -1
57 };
58 
59 String GetTraFileErrorText(TraFileErrorType err);
60 String GetTraBlockName(TraFileBlock id);
61 
62 typedef TypedCodeError<TraFileErrorType, GetTraFileErrorText> TraFileError;
63 
64 
65 struct Translation {
66 	// Game identifiers, for matching the translation file with the game
67 	int GameUid;
68 	String GameName;
69 	// Translation dictionary in source/dest pairs
70 	StringMap Dict;
71 	// Localization parameters
72 	int NormalFont = -1; // replacement for normal font, or -1 for default
73 	int SpeechFont = -1; // replacement for speech font, or -1 for default
74 	int RightToLeft = -1; // r2l text mode (0, 1), or -1 for default
75 	StringMap StrOptions; // to store extended options with string values
76 };
77 
78 
79 // Parses translation data and tests whether it matches the given game
80 HError TestTraGameID(int game_uid, const String &game_name, Stream *in);
81 // Reads full translation data from the provided stream
82 HError ReadTraData(Translation &tra, Stream *in);
83 // Writes all translation data to the stream
84 void WriteTraData(const Translation &tra, Stream *out);
85 
86 } // namespace Common
87 } // namespace AGS
88 } // namespace AGS3
89 
90 #endif
91