Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scummfont): Stop outputting a -new file by default #26

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions man/scummfont.1
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ Import the content of an
.Pa image.bmp
bitmap file into the specified
.Ar FONTFILE
SCUMM resource, with a
.Dq -new
suffix added to it.
SCUMM resource.
.It Cm o
Extract a font from a
.Ar FONTFILE
Expand Down
22 changes: 19 additions & 3 deletions src/ScummFont/scummfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int usage()
std::cout << " scummfont {i|o} font bitmap.bmp" << std::endl;
std::cout << std::endl;
std::cout << " o: Export bitmap.bmp from font" << std::endl;
std::cout << " i: Import bitmap.bmp into font (result written in font-new)" << std::endl;
std::cout << " i: Import bitmap.bmp into font" << std::endl;
std::cout << std::endl;
std::cout << "\"font\" is either a CHAR block extracted with scummrp, or an LFL file" << std::endl;

Expand Down Expand Up @@ -241,6 +241,15 @@ static std::string tmpPath(const char *path)
return s;
}

static void renameAndRemoveOriginal(const char *from, const char *to)
{
if (remove(to) != 0) // for Win32
throw std::runtime_error("Can't replace the existing font: remove failed");

if (rename(from, to) != 0)
throw std::runtime_error("Can't replace the existing font: rename failed");
}

static inline int roundTo4(int i)
{
return (i + 3) & ~0x3;
Expand Down Expand Up @@ -308,6 +317,8 @@ static void saveBmp(const char *path)
memcpy(buf + i * roundTo4(glWidth), glFontBitmap + (glHeight - i - 1) * glWidth, glWidth);

file.write((char *)buf, roundTo4(glWidth) * glHeight);

file.close();
}

static void loadBmp(const char *path)
Expand Down Expand Up @@ -360,6 +371,8 @@ static void loadBmp(const char *path)
file.read((char *)buf, roundTo4(glWidth) * glHeight);
for (int i = 0; i < glHeight; ++i)
memcpy(glFontBitmap + i * glWidth, buf + (glHeight - i - 1) * roundTo4(glWidth), glWidth);

file.close();
}

static void saveFont(const char *path)
Expand Down Expand Up @@ -522,6 +535,8 @@ static void saveFont(const char *path)
++endOffset;
}
}
file.close();

if (baseOffset == 8) // block header
{
tmpFile.seekp(0x4, std::ios::beg);
Expand Down Expand Up @@ -550,9 +565,9 @@ static void saveFont(const char *path)
numChars = newNumChars;
tmpFile.write((char *)&numChars, 2);
}
tmpFile.close();

std::cout << "Output file has been written to " << tmpfilepath << std::endl;
std::cout << "Don't forget to replace your original file with the new version" << std::endl;
renameAndRemoveOriginal(path, tmpfilepath.c_str());
}
}

Expand Down Expand Up @@ -652,6 +667,7 @@ static void loadFont(const char *path)
mask = b = p = 0;
}
}
file.close();
}

int main(int argc, char **argv) try
Expand Down
3 changes: 2 additions & 1 deletion src/ScummRp/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void xremove(const char *path)
}
}

// note: newname must not already exist. call xremove() beforehand if necessary.
// note: because of Win32, newname must not already exist. Call xremove()
// beforehand if necessary.
void xrename(const char *oldname, const char *newname)
{
if (rename(oldname, newname) != 0)
Expand Down