[Pre-release] D2MFC & D2FTM, Modern Font Customize solution for Diablo II

This would be the forum for questions about how to work with mod making tools which can be a problem of its own.

Moderator: Paul Siramy

Cai_Miao-BTH
Posts: 90
Joined: Mon Sep 23, 2013 10:04 am
Location: China
China

[Pre-release] D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Post by Cai_Miao-BTH » Wed Apr 15, 2020 9:47 pm

EDIT: as previously announced at PK Discord server, it is now open-sourced at github.
https://github.com/346lab/D2MFC

the unmodified code of this release is at [dev] branch.
the default [json] branch introduces a dirty json support modified by me.

regarding code, all rights reserved at the moment.
status may change in future.

-----

Brand new font generation tool with one cmd line

This is the early stage version of the d2mfc program, it's basically good for latin-only fonts. enjoy...

Download: https://drive.google.com/open?id=1lnJyN ... wPexcanUuE

An Cascade Code font, which is under the SIL Open Font license, is packed along with the archive for test purpose.

Cascade Code: https://github.com/microsoft/cascadia-code

Read README.md in the archive for instructions.

Image
# Modern Font Customize solution for Diablo II

*Presented by EAirPeter (dev) & Cai_Miao (design)*

## D2MFC - tool for Diablo II Modern Font Creation

Have you worried about a set of workflow which is complicated to making a shiny new font for your mod project?

Did you ever try to localize D2 in your language but at last gave up when you find you need a extended font to support your language?

This is the **salvation**.

*Note: D2FTM-Kai is the develop code for D2MFC, as it was developed after the D2FTM.*

*Note: D2MFC is planned to be eventually open-sourced*

### Feature

- Generate dc6/tbl pairs of a font with only 1 command line!
- FreeType based, with proper ascent/descent/bearing/advance handling

### Usage
```
D2FTM-Kai.exe <FirstCodePoint> <LastCodePoint> <FontFacePath> <PointSize> <Palette>.dat <Out>.dc6 <Out>.tbl
Construct DC6 and TBL file using the specified font face and point size.
Note: The font must be supported by FreeType.
Use null as the palatte to encode as grayscale images.
```

sample command:
```
.\D2FTM-Kai.exe 0 254 "C:\Windows\font\consola.ttf" 14 act1-fechar.dat font16.dc6 font16.tbl 2> nul
```

`CodePoint`: refers to the Unicode codepoint in decimal, use [the Unicode table](https://unicode-table.com/) wisely

`FontFacePath`: path to a font file. Can't just define a font family name at this time (probably never)

`PointSize`: actually glyph width in pixel, height will be automatically determined

`Palette`: a .dat pallete for color quantization. Currently we provide a modified palette, `act1-fechar.dat`, for you to use, covering 99% conditions (might be, i'm not responsible for the estimating)

`Out`: you know what

`2> nul`: You might need this to supress massive warning echoes, believe me

### Known issue

- Can't determine the color for now, it's fixed #000 for bg and #FFF for glyph.

- You might encounter `Freetype call failed: FT_Load_Char` error when you generate font, it's because one or more codepoints in the range does not being assigned in the font. You can try `126` as `LastCodePoint` when you generate fonts for basic alphabets only.

- Only one codepoint range can be specify for now, so you might unable to generate through glyphs of your language or generating huge amount of redundant glyphs you will never use.

- Leading (a.k.a. line spacing) is likely to be too high. Use D2FTM to manually patch this.


---

## D2FTM - Diablo II Font Table Master

This is a side project before D2FTM was born, it is developed to fiddle the tbl for fonts, without wasting time on your hex editor, and giving a bit more advanced function to it.

### Feature

- Converts from TBL file to TXT file or vice versa. (The direction of the conversion is determined by the extension of the input file)
- escaping characters for `\t`, `\n` and `\r`
- Values in a character entry can use another char's value, referring with `#<char>` in TXT when compiling TBL.
- Open-sourced (not a feature though)

### Usage

```
Diablo II Font Table Master
by EAirPeter, CaiMiao

Usage: .\D2FTM.exe <Input>.tbl <Output>.txt
.\D2FTM.exe <Input>.txt <Output>.tbl
.\D2FTM.exe <Input>.tbl
.\D2FTM.exe <Input>.txt

Convert from TBL file to TXT file or vice versa. (The direction of the conversion is determined by the extension of the input file)
```
Due to the command, you can just drag&drop tbl/txt on the exe to convert.

### Valid txt structure

*generally this is a tab-seperated csv*
```
Woo! <the nLocale> <TocalChar> <Leading> <CapHeight>
<char> <width> <height> <the bTrue> <Dc6ImageIndex>
<char> <width> <height> <the bTrue> <Dc6ImageIndex>
<char> #<refChar> #<refChar> #<refChar> #<refChar>
...

```

`Woo!`: old magic string

`TocalChar`: total characters in the font, it's automatically set to correct value if you have more or less amount of character entries so it's actually FYI purpose

`Leading`: You may always need to adjust this if you use D2MFC. Note that this is not the final value. See below to calculate final leading

`CapHeight`: *the Font table standard ™* claims it is. Modify this if you want to see what's happening.

`Dc6ImageIndex`: mainly FYI when looking for corresponding glyph in dc6 creator, but you can also modify this

*and so forth, lazy to reprint, you can also refer [the Font table standard ™](viewtopic.php?f=6&t=42044).*

`#<refChar>`: see below for the advanced referencing

### The leading formula

*credits to Necrolis*

TLDR: TBL leading = (determined leading in pixel / 1.5) + 1 (decimals round up)

#### Detail

`final leading = (font height constant of your target language * tbl leading) / 10`

The constant for Latin language should be `17`, others can see the table below.

```
DEFAULT (Latin) = 17
English (ENG,0x00) = 17

Japanese (JPN,0x06) = 15
Korean (KOR,0x07) = 17
Singporean Simplified Chinese (SIN,0x08) = 14
Traditional Chinese (CHI,0x09) = 14
Polish (POL, 0x0a) = 13
Russian (RUS, 0x0b)= 17
```

## the advanced referencing

```
Woo! 0 65535 14 14
4 4 0 0032
! 4 15 0 0033
" 5 14 0 0034
# 11 14 0 0035
a #! #! 0 #!
Z #! #! 0 #!
```

If you do like this, `a` and `Z` in game will show an exactly `!`

## Warning/Known Issue

- Latin fonts are restricted to 0000-00FF unicode block and 255 chars max. Any char goes beyond that won't load by game, if you want to go through 0100-FFFF then use non-Latin language

- You should have your entries in strict Unicode order, otherwise chars of scrambled part and forth won't load by game

- you can only refer char entries before current char
Last edited by Cai_Miao-BTH on Mon Jan 04, 2021 10:07 am, edited 4 times in total.
Translator for Simplified Chinese.
Discord: cai_miao#0861
Translated BTH by onyx, HU by Soulmancer (until 2.x),
LRdO (approved) by Xaphan and Median XL: Sigma by the MXL community.
D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Future project:
- Set of Font with FULL Latin, CHI, JAP and RUS character support. To much time needed.
- BFE by TrueMage - to Simplified Chinese from English
- ES (original) by PerfectCell to Simplified Chinese from English/Japanese
-Touhou Diablo by Bishibosh-A - to English/Japanese from Chinese

User avatar
Wasp
Posts: 3
Joined: Wed Jun 05, 2019 1:33 pm
France

Re: D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Post by Wasp » Wed Apr 15, 2020 9:48 pm

Good job mate :D

User avatar
eleriaqueen
Posts: 57
Joined: Mon Dec 16, 2019 8:49 am
France

Re: [Pre-release] [Alpha] D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Post by eleriaqueen » Sat Apr 25, 2020 4:19 pm

This looks like a very nice tool !

User avatar
eleriaqueen
Posts: 57
Joined: Mon Dec 16, 2019 8:49 am
France

Re: [Pre-release] [Alpha] D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Post by eleriaqueen » Sat Oct 31, 2020 7:51 am

Any update planned for this tool ? I just tried it and had a weird issue where inputting 11 or 13 for Lead-in would result in some item description starting with a blank gap (when inputting 10 or 12 seems to work fine). Aside from that this tool is insanely good !
Would also love to be able to configure font's maximum white value as the original D2 font16 uses rgb(196,196,196) while D2FTM uses rgb(244,244,244) which is a bit too bright.
I'd also like to say going Open Source would be really nice, too many tools in the overall games-modding scene stay closed-source and can never be updated once the author vanishes.

Edit : I made an "omni-batch-script" to work with these tools, drag and drop your .ttf file onto the batch file and wait !
(Create a .bat file and add your paths to D2FTM, D2FTM-KAI, to the Palette before saving) :

Code: Select all

@echo off
set d2ftmkai="Full_Path_to_D2FTM-KAI"
set d2ftm="Full_Path_to_D2FTM"
set typeface="%~1"
set palette="Full_Path_to_Palette"

echo Converting typeface into DC6 / TBL pairs
%d2ftmkai% 0 254 %typeface% 8 %palette% font6.dc6 font6.tbl 2> nul
%d2ftmkai% 0 254 %typeface% 12 %palette% font8.dc6 font8.tbl 2> nul
%d2ftmkai% 0 254 %typeface% 14 %palette% font16.dc6 font16.tbl 2> nul
echo.
echo Extracting Txt offsets from Tbl
%d2ftm% .\font6.tbl
%d2ftm% .\font8.tbl
%d2ftm% .\font16.tbl
pause

Cai_Miao-BTH
Posts: 90
Joined: Mon Sep 23, 2013 10:04 am
Location: China
China

Re: [Pre-release] D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Post by Cai_Miao-BTH » Mon Jan 04, 2021 10:13 am

eleriaqueen wrote:
Sat Oct 31, 2020 7:51 am
Any update planned for this tool ? I just tried it and had a weird issue where inputting 11 or 13 for Lead-in would result in some item description starting with a blank gap (when inputting 10 or 12 seems to work fine). Aside from that this tool is insanely good !
Would also love to be able to configure font's maximum white value as the original D2 font16 uses rgb(196,196,196) while D2FTM uses rgb(244,244,244) which is a bit too bright.
I'd also like to say going Open Source would be really nice, too many tools in the overall games-modding scene stay closed-source and can never be updated once the author vanishes.
hi, it was open-sourced at github. sorry for late update.
i can't do much change of the code as i am not actually dev on this, you make look at the code and see what you can do.
freetype renders the bitmap in greyscale, so you might need to do a color mapping during the bitmap gen process.
Translator for Simplified Chinese.
Discord: cai_miao#0861
Translated BTH by onyx, HU by Soulmancer (until 2.x),
LRdO (approved) by Xaphan and Median XL: Sigma by the MXL community.
D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Future project:
- Set of Font with FULL Latin, CHI, JAP and RUS character support. To much time needed.
- BFE by TrueMage - to Simplified Chinese from English
- ES (original) by PerfectCell to Simplified Chinese from English/Japanese
-Touhou Diablo by Bishibosh-A - to English/Japanese from Chinese

User avatar
eleriaqueen
Posts: 57
Joined: Mon Dec 16, 2019 8:49 am
France

Re: [Pre-release] D2MFC & D2FTM, Modern Font Customize solution for Diablo II

Post by eleriaqueen » Wed Jan 06, 2021 8:03 pm

Thanks for the info, I have limited skills in C programming but I'll take a look at the code.

Return to “Tools”