Isolate grtext submodule

Isolate grtext from rest of the project, minor cleanups.
This commit is contained in:
Azamat H. Hackimov 2024-07-28 00:50:49 +03:00
parent 87882c9976
commit 7b31572d05
17 changed files with 55 additions and 61 deletions

View File

@ -1,12 +1,17 @@
set(HEADERS grtextlib.h)
set(CPPS
grfont.cpp
grtext.cpp
textaux.cpp)
textaux.cpp
)
add_library(grtext STATIC ${HEADERS} ${CPPS})
add_library(grtext STATIC ${CPPS})
target_link_libraries(grtext PRIVATE
ddio
mem
misc
)
target_include_directories(grtext PUBLIC
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/grtext
>
)

View File

@ -107,18 +107,18 @@
* $NoKeywords: $
*/
#include "grtextlib.h"
#include "cfile.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include "bitmap.h"
#include "cfile.h"
#include "ddio.h"
#include "grtextlib.h"
#include "mem.h"
#include "pserror.h"
#include "renderer.h"
#include "mem.h"
#include "ddio.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
const int MAX_FONTS = 16, MAX_FONT_BITMAPS = 32;
@ -185,7 +185,7 @@ inline FONTFILE OPEN_FONT(const char *filename) {
fp = (FONTFILE)cfopen(filename, "rb");
if (!fp)
return NULL;
return nullptr;
file_id = READ_FONT_INT(fp);
if (file_id != 0xfeedbaba)
@ -225,7 +225,7 @@ inline FONTFILE2 OPEN_FONT2(const char *filename) {
fp = (FONTFILE2)fopen(filename, "wb");
if (!fp)
return NULL;
return nullptr;
return fp;
}
@ -333,9 +333,8 @@ int grfont_Load(const char *fname) {
fnt.char_widths = (uint8_t *)mem_malloc(sizeof(uint8_t) * num_char);
for (i = 0; i < num_char; i++)
fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ff);
// mprintf(0, "::proportional");
} else {
fnt.char_widths = NULL;
fnt.char_widths = nullptr;
}
// Read in kerning data
@ -351,7 +350,7 @@ int grfont_Load(const char *fname) {
fnt.kern_data[i * 3 + 1] = 255;
fnt.kern_data[i * 3 + 2] = 0;
} else {
fnt.kern_data = NULL;
fnt.kern_data = nullptr;
}
// Read in pixel data.
@ -490,7 +489,7 @@ bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) {
for (i = 0; i < num_char; i++)
ft->ch_widths[i] = (uint8_t)READ_FONT_SHORT(ff);
} else {
ft->ch_widths = NULL;
ft->ch_widths = nullptr;
}
if (ft_flags & FT_KERNED) {
@ -529,11 +528,11 @@ bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) {
void grfont_FreeTemplate(tFontTemplate *ft) {
if (ft->kern_data) {
mem_free(ft->kern_data);
ft->kern_data = NULL;
ft->kern_data = nullptr;
}
if (ft->ch_widths) {
mem_free(ft->ch_widths);
ft->ch_widths = NULL;
ft->ch_widths = nullptr;
}
}
@ -582,7 +581,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) {
for (i = 0; i < num_char; i++)
fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ffin);
} else {
fnt.char_widths = NULL;
fnt.char_widths = nullptr;
}
// Read in kerning data
@ -598,7 +597,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) {
fnt.kern_data[i * 3 + 1] = 255;
fnt.kern_data[i * 3 + 2] = 0;
} else {
fnt.kern_data = NULL;
fnt.kern_data = nullptr;
}
// Read in pixel data.
@ -655,7 +654,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) {
// Write widths now if necessary.(FT_PROPORTIONAL)
if (fnt.flags & FT_PROPORTIONAL) {
for (int i = 0; i < num_char; i++)
for (i = 0; i < num_char; i++)
WRITE_FONT_SHORT(ffout, (int16_t)fnt.char_widths[i]);
}
@ -698,7 +697,7 @@ bool grfont_SetKerning(int font, uint8_t *kern_data) {
// reset kerning...
if (oldft->font.kern_data) {
mem_free(oldft->font.kern_data);
oldft->font.kern_data = NULL;
oldft->font.kern_data = nullptr;
}
if (kern_data) {
@ -1087,7 +1086,7 @@ uint16_t *grfont_GetRawCharacterData(int font, int ch, int *w, int *h, bool *mon
}
if ((ch < fnt->font.min_ascii) || (ch > fnt->font.max_ascii))
return NULL;
return nullptr;
ch = ch - fnt->font.min_ascii;
*mono = !(fnt->font.flags & FT_COLOR);

View File

@ -148,16 +148,12 @@
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <cctype>
#include "grtextlib.h"
#include "renderer.h"
#include "pserror.h"
#include "mem.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "renderer.h"
#define CLIP_LEFT Grtext_left
#define CLIP_TOP Grtext_top
@ -222,12 +218,12 @@ static bool grtext_FilterProfanity = false;
void grtext_SetProfanityFilter(bool enabled) { grtext_FilterProfanity = enabled; }
// Right now this just decrypts the bad words
void grtext_Init(void) {
for (int i = 0; i < NUM_BAD_WORDS; i++) {
void grtext_Init() {
for (auto & bad_word : bad_words) {
int pos = 0;
while (bad_words[i][pos]) {
bad_words[i][pos] = bad_words[i][pos] ^ XORVAL;
while (bad_word[pos]) {
bad_word[pos] = bad_word[pos] ^ XORVAL;
pos++;
}
}
@ -340,7 +336,6 @@ void grtext_SetFontScale(float scale) {
void grtext_SetFancyColor(ddgr_color col1, ddgr_color col2, ddgr_color col3, ddgr_color col4) {
struct {
char op;
// ddgr_color col[4];
ddgr_color col;
} cmd;
@ -478,10 +473,10 @@ void grtext_Puts(int x, int y, const char *str) {
lowerstr[slen] = '\0';
for (int i = 0; i < NUM_BAD_WORDS; i++) {
char *p = strstr(lowerstr, (char *)bad_words[i]);
for (auto & bad_word : bad_words) {
char *p = strstr(lowerstr, (char *)bad_word);
while (p) {
int len = strlen((char *)bad_words[i]);
int len = strlen((char *)bad_word);
char *realp = (char *)((int)(p - lowerstr) + &Grtext_buffer[Grtext_ptr]);
for (int a = 0; a < len; a++) {
ASSERT(p);
@ -489,7 +484,7 @@ void grtext_Puts(int x, int y, const char *str) {
*p = *realp;
realp++;
}
p = strstr(lowerstr, (char *)bad_words[i]);
p = strstr(lowerstr, (char *)bad_word);
};
}
// DAJ mem_free(lowerstr);

View File

@ -108,7 +108,8 @@
#ifndef GRTEXT_H
#define GRTEXT_H
#include "pstypes.h"
#include <cstdint>
#include "ddvid.h"
#define GRTEXT_BUFLEN 16384
@ -282,7 +283,7 @@ int grfont_GetTracking(int font);
/////////////////////////////////////////////////////////////////////
// Init functions -- call before anything is rendered!
void grtext_Init(void);
void grtext_Init();
#ifndef RELEASE
void grfont_Spew(int font, int x, int y);

View File

@ -38,8 +38,9 @@
#ifndef GRTEXTLIB_H
#define GRTEXTLIB_H
#include <cstdint>
#include "grtext.h"
#include "pstypes.h"
struct tCharBlt {
uint16_t ch;

View File

@ -49,10 +49,10 @@
* $NoKeywords: $
*/
#include <cstdio>
#include <cstring>
#include "grtext.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
// textaux_WordWrap
//
@ -127,14 +127,14 @@ const char *textaux_CopyTextLine(const char *src, char *dest) {
if (!src) {
if (dest)
dest[0] = '\0';
return NULL;
return nullptr;
}
if (!dest)
return NULL;
return nullptr;
// see if we are at the end of the src
if (src[0] == '\0') {
dest[0] = '\0';
return NULL;
return nullptr;
}
int i;
i = 0;
@ -145,7 +145,7 @@ const char *textaux_CopyTextLine(const char *src, char *dest) {
// no more lines left after this
strncpy(dest, src, i);
dest[i] = '\0';
return NULL;
return nullptr;
} else {
// we hit a newline char
strncpy(dest, src, i);

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -27,6 +27,7 @@ set(CPPS
add_definitions(-DOUTRAGE_VERSION)
add_library(dmfc STATIC ${HEADERS} ${CPPS})
target_link_libraries(dmfc PRIVATE
target_link_libraries(dmfc PUBLIC
grtext
misc
)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m")
target_link_libraries(${NETGAME_MODULE} PRIVATE
dmfc
misc
)
install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames)

View File

@ -19,6 +19,7 @@ set(CPPS
add_library(ui STATIC ${CPPS})
target_link_libraries(ui PRIVATE
ddio
grtext
mem
misc
)