PC Mode
Org Mobile Site
Forum > Medieval 2: Total War > Medieval 2: Total War > M2:TW Modification > Learn to Mod > Modding Tutorials & Tools >
Thread: Release of the CUF (font & text rendering) mod tool
Tellos Athenaios 20:46 05-12-2010
The Europa Barbarorum Team hereby releases the results of its efforts to open up the CUF file format for modding. The “CUF” project provides modders with tools to create their own CUF fonts as well as incorporate basic support for “rich text” in their mods. Originally developed for manipulating the CUF fonts bundled with these games, the “CUF” project has progressed so far we believe that others would want to use this tool for their own purposes as well. A screenshot or two may help to explain why we feel that such confidence is justified:



The tool allows you to convert TrueType or Type1 fonts to a CUF file; as well as make more advanced use of the strings.bin format in tandem with the CUF format to manipulate the way descriptions are rendered and produce multiple font styles alongside each other in the same “body” of text. The screenshot above shows how that might look.

The project can be downloaded from our FTP server right here: ftp://europabarbarorum.org/CUF-src-dist.7z. The download consists of a single compressed 7zip archive containing:

Programs such as 7-zip can be used to extract these contents. (You can get 7-zip from here: http://www.7-zip.org/ or commandline equivalent p7zip from here: http://p7zip.sourceforge.net/ )

People who do not want to build from source can download the following compressed 7-zip archive instead: ftp://europabarbarorum.org/CUF-bin-dist.7z. This version contains:


Both versions (source and binary only) are made available under the following licence:
Originally Posted by :
Copyright (c) 2010, The Europa Barbarorum Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of The Europa Barbarorum Team nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL The Europa Barbarorum Team BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Our knowledge of the CUF file format is by no means infallible; as is evident from the screenshot marking most CUF properties as `purpose unknown'. This obviously reflects on how the end result looks compared to a preview generated by the tool: while the preview is roughly accurate, it is necessarily a simplified render and thus does not reflect the precise rendering method of the game engine. Consequentially precise text alignment is at the moment somewhat hit & miss and best results come from using font sizes that correspond with the fonts used by CA.[*] Further research in the details of CUF font rendering as it is performed by the M2TW engine will be required to make the results more robust in this regard.

Comments, criticism, improvements and bug reports are welcome. Regards,

The Europa Barbarorum Team.

* Note that alignment does not refer to how individual glyphs align with each other; rather it refers to how a line of text aligns to its bounding box (e.g. how a label aligns on a button).

Reply
Tellos Athenaios 20:58 06-18-2010
Pushed out an update to the files on the EB FTP server (since the links in post #1 point to those, these are automatically updated as well).

A summary of the changes:

New Features

Bugfixes

Misc changes

... and anything I might have forgotten. Also a screenshot that showcases tab support:


Reply
Tellos Athenaios 00:08 06-29-2010
Updated the tool with a fix to ensure order of records read from strings.bin files is preserved; added option to warn about empty strings in records.

Changed the compression method of the download, to XZ which promises better compression.

The binary-only download is now an XZ compressed archive, too: you can find the JAR file inside it as dist/CUF.jar.
Spoiler Alert, click show to read: 
I changed the contents of the binary distribution: now, you get copies of COPYRIGHT and readme.html files as well as pre-built program documentation outside the JAR file as well (all in all these additions about double the size to 536KB).


Reply
Tellos Athenaios 23:32 07-14-2010
Another update, another changelog. This one brings:



Reply
Tellos Athenaios 10:02 08-01-2010
Updated the tool again, this time it contains the following changes:

Improved support for Windows:
  1. Build scripts use native2ascii which means compiling the tool from source is considerably easier.
  2. Tool forces the use of UTF-8 encoding internally, which fixes some visual glitches on Windows.
  3. Added a Windows Script Host launch script, written in JScript. This means that unless Windows Script Host has been explicitly disabled or something similar, you can use that script on Windows the same way you can use the POSIX sh script with a sh interpreter.


Other changes:
  1. Added filtering of output for some progress messages: turning the “ChattyShell” preference to off (false), and the number of progress messages will be considerably reduced for large fonts.\
  2. Improved character encoding handling when compiling Strings files: due to some internal changes you can now leave encoding fields blank and let underlying parsers “guess” or (“detect”) the right character encoding in use. One particular benefit of this is that byte order marks are now mostly harmless in XML documents if you do not specify a character encoding yourself (previously you could get a content not allowed in prolog message or similar).
  3. Added dialogs to the CUF shell GUI to run scripts.
  4. Added support for wrapping multiple URI-resolvers in a single one, which is useful in conjunction with a KeyResolver.
  5. Added support for compiling M2TW-style tagged files. Note that it is not at all as robust as compiling from XML files. In StringsToolkit, use the compile() method which takes input file name, output file name, a KeyResolver and a boolean flag to use this feature.
  6. Added IdentityMapping (a kind of StringMapping) which allows you to compile without macros (Macro files): it simply passes its input text on to the other layers of the compiler.


Reply
Mataputas 04:15 08-13-2010
I'm really interested in your project. Should it work for Rome Total War engine?

Reply
Tellos Athenaios 03:58 08-14-2010
Depends on whether the version of Rome Total War you have contains CUF files (with .cuf extension).
Mine (plain old vanilla) doesn't, but maybe one of the extensions (BI or Alexander) does?


You can check whether they will work (if you have them) by trying to preview them. If that appears to work OK (you get a nice preview rendered in the given font), it means that your CUF files from RTW are structured the same way as those from M2TW and that in turn means you can use the program to create your own replacement fonts.

Reply
Tellos Athenaios 18:36 08-14-2010
Pushed out a minor update which improves upon the tool in several small ways:

In FontToolkit (org.europabarbarorum.cuf.shell.FontToolkit):


Changed TopLevelSource (org.europabarbarorum.cuf.font.TopLevelSource) to be merely a complementary interface to CUFSource (org.europabarbarorum.cuf.font.CUFSource). In the unlikely event you were using it to inherit the contract for CUFSource methods in addition to its own interface contract, this will break your script. But the good news is:

I made various CUFSource implementations (MappedSource, RestrictedSource, AbstractCUFSource, and MixedSource) more generic. Hence if you were/are/will-be using a custom implementation of CUFSource you should now find these a lot easier to work with.

Reply
Tellos Athenaios 01:41 08-22-2010
New update:

Fix: missing format specifier for nested namespaces. So if you made that error you now get the proper error message.
New: font previews/GUI now use a more understandable notation for decimal values & editing works.
New: marker lines which you can use to judge the effect of layout offset settings on GUI.

Reply
nedensiz1 16:30 08-26-2010
Hi, I have a problem about M2TW Fonts:

Three monts ago I and some of my friends decided to translate M2TW into Turkish. We created a translation group in our web site and started to work on it. We translated some of M2TW files and we have made some progress. But we encountered some problems while translating. We can't use some letters like "Ğ", "ğ", "İ", "Ş", "ş" (which placed in our Turkish alphabet) in some of the text files.

For example: I tried to change Iconium city name in "imperial_campaign_regions_and_settlement_names.txt" file:


Result: I can't see city name on the top


Is there any way to use these letters, add them into M2TW fonts, change some fonts, maybe change font style or something like that?

I tried to edit some fonts on my computer with TypeTool program but it didn't work.

Codes:


We will be happy If you can help us, thanks.

Reply
Tellos Athenaios 18:39 08-26-2010
The reason & fix are simple enough:

Reason: the fonts used by CA for these titles (kp_14.cuf, kpl_60.cuf kp_18.cuf) do not support those characters. As a result they are not rendered.
Fix: create your own CUF files based off a font that does support those characters.

Reply
nedensiz1 19:07 08-26-2010
You are right, I tried to use your mod and saw that kp_14.cuf, kpl_60.cuf kp_18.cuf files does not support that those letters.

I am sorry, I dont understand programing Java or etc. And how can I make my own cuf file? Is it possible with this program?

* Sorry for the same post on twc.

Reply
nedensiz1 19:49 08-26-2010
I renamed the "font_14.cuf" font as "kp_14.cuf" font and "font_18.cuf" font as "kp_18.cuf" font. It works but I think, I need to change their font size 1 pixel lower. Can you help me please?

Reply
Tellos Athenaios 05:01 08-27-2010
Originally Posted by nedensiz1:
You are right, I tried to use your mod and saw that kp_14.cuf, kpl_60.cuf kp_18.cuf files does not support that those letters.

I am sorry, I dont understand programing Java or etc. And how can I make my own cuf file? Is it possible with this program?

* Sorry for the same post on twc.
Yes it is possible, in fact I would say that it is more or less the point of the program ()[*]. I know the readme.html file is big and perhaps not too useful when you think “help I don't know anything help me please”. Though, on the upside it contains snippets of code where all you have to do copy + pase & change a few values and you are good to go for a simple CUF file. Or if you are really desperate for a ready made sample:
Code:
importPackage(org.europabarbarorum.cuf.shell); // get the tools we need
var sysFont = new FontStyle("Lucida Sans Unicode", 24); // define a font
sysFont.bold(); // make it bold.

var cufFont = sysFont.getFont(shell); // convert it into something we can save to a CUF file.

FontToolkit kit=new FontToolkit(shell); // toolbox containing lots of handy features.

var job = kit.compile(cufFont, "lucida-sans-unicode-bold-24.cuf"); // create a job for the CUF compiler which will save our font.
job.attach(shell); // ensures that the shell is disposed of after the script finishes. If it is the only shell currently in use it means that the program will exit after compilation has finished.
job.run(); // run compilation: a lot of progress messages will appear.
[*] The program works roughly as follows: you type in commands which it runs (or you supply it a script which it then runs), and apart from that there is a large library of predefined commands/functions/tools/stuff that make it a lot easier to work with CUF files (and strings.bin files).

Reply
Tellos Athenaios 05:07 08-27-2010
Originally Posted by nedensiz1:
I renamed the "font_14.cuf" font as "kp_14.cuf" font and "font_18.cuf" font as "kp_18.cuf" font. It works but I think, I need to change their font size 1 pixel lower. Can you help me please?
One pixel lower as in it must be positioned one pixel lower? Or as in: the font is too big? If you mean the latter that is a lot of work, it is much easier to simply generate a new font. The reason is that the CUF files contain all the glyphs (characters if you will) as rendered alpha masks (and other information required to make sense of them), so scaling those down to look 1px smaller is at best a lot of work for little gain (the visual quality of the glyphs will not improve with such butchery).

Reply
nedensiz1 15:34 08-27-2010
Ok, I will try to make my own .cuf fonts. Thanks.

Reply
Tellos Athenaios 22:43 09-13-2010
I'm back with another update. Pretty big one this time around:

CUF files


Font previews


CUF Shell:


Help files (need more work to be a proper reference documentation):

The Help feature requires JavaHelp, which you can get from here: https://javahelp.dev.java.net/

Misc:


Reply
Tellos Athenaios 21:28 10-11-2010
Pretty big update:

Features
  1. Support for JLine. This provides the program with some readline functionality when it runs directly from the command line.
  2. Added a “Fontwizard” GUI which provides a for a simpeler way to produce fonts than by writing your own scripts. You can find it under the Build menu. It is a bit rough round the edges, but
    sufficient for quickly building a font or mocking up something. Use the Export buttons to pop up a dialog for previewing/saving your work.
  3. Added more extensive logging capabilities to the program/software through IOHelp.Log.


Restructured code layout
Lots of the auxiliary code has been restructured due to the additions of Fontwizard, JLine support and better logging.

A particular item of interest is that the code which handles program settings has been moved from org.europabarbarorum.cuf to org.europabarbarorum.cuf.support, and
that it is now confined to the Setting class (the Prefs class merged with the Setting interface into the Setting class), and the specific program
settings moved to the modules that actually use them.

The upshot of these changes is that if you have script code which manipulates program settings directly you will need to update it.

Another item of interest are the various restrict() methods in FontToolkit: these require now an addition boolean parameter. Old code which used these operations
should use “true” here (this yields equivalent behavior to previous versions of these restrict() methods). Use “false” to invert the result of the old style
restrict() methods.

Bugs
  1. CUFWriter catches a couple more errors you might make and fails with an error message of its own.
    So although the net result will be largely the same, at least you will have a useful error message to work wih.
  2. The control character font now sets the number of glyphs it contains, along with a slight change in CUFWriter's behaviour this
    fixes two edge-cases: a) that CUFWriter previously could fail seemingly random (but see above) if no glyphs were declared on the font,
    b) that someone might actually want to use the control character font more directly.
  3. Add missing check & default values in CUFRenderPanel when looking up certain CUFProperty settings.
  4. Fix Classloader to not load classes that the JVM has already loaded. Prevents doing double work as well as duplicating shared resources.


Reply
Tellos Athenaios 07:33 11-19-2010
Important update. This update contains a fix for a bug in the code which generated “keyed” strings.bin files. This fix involves generating proper lookup tables at the end of the file: without those Medieval II/Kingdoms suffer significant performance penalties. Mea culpa, the code that generated the strings.bin files was based off alpaca's bin converter which does not (nor does it need to) deal with this. I would like to thank my fellow EB members who tested and suffered the performance hit for their patience and help in debugging the problem, in particular Atilius and bobbin. Thanks, guys!

Apart from having a fix which brings performance back to something more reasonable, the silver lining here is that this fix also addresses a bug in the Medieval II/Kingdoms files. Apparently the data/text/export_units.txt.strings.bin files extracted from the game packs are not built correctly either (implying that the game does not convert export_units properly). The lookup table in this file does not refer to the source code, rather it contains a dump of 795 entries for the 265 RTW units from RTW Vanilla (795 = 265 *3, and there are 3 keys per unit in export_units data.)

This update also contains a simplification of the strings compiler, so the StringsSource types are no longer required. As a result if you were using StringsSources directly, you will need to update to use StringsFeeders. Furthermore setOrder(boolean) in StringsToolkit is gone and replaced with format(String). You can use “Ordered” where previously you would use “true”.

Furthermore this update incorporates some of the improved understanding of the CUF file format, with regards to certain CUF properties. These are “maximum width” and “maximum height” of glyphs. This means that the suitable values will be automatically inferred by the CUF compiler by default. This behaviour can be controlled/disabled per property through CUFWriter.SetVSize, CUFWriter.SetHSize and CUFWriter.SetGlyphDataSize options: see Javadoc for details.

This behaviour is new for VSize and HSize properties, both of which refer to cut-off values (if a glyph is wider or taller than either value it appears cut off in the game). The code rendering the previews in the tool do not take these values into account yet. For GlyphDataSize property it means you now have the final control over what is written to the CUF file.

Reply
Tellos Athenaios 20:47 12-21-2010
There's a new important update available. This one fixes a few serious issues, and one less so.
[list]
New features:

Bugs:

Misc:


Reply
Tellos Athenaios 07:53 01-07-2011
There is another update of the tool. This update changes how sub shells interact with each other. Shells now live in their own thread (as managed by the JVM) rather than as task in a thread pool (as managed on top of the JVM). This update also fixes the long standing bug of output messages appearing out-of-order when running multiple shells in parallel.

The result is a tool which is able to tax the CPU more aggressively when a lot of shells are forked, and thus finish parallel tasks faster. Subjectively, the command prompt feels faster from the GUI, as well.

There are a few other minor changes:


Reply
Tellos Athenaios 05:49 01-14-2011
Update of the tool. The update itself is fairly small, but the main changes are worth updating for: a bug squashed and the tool is easier to use.

Main changes


Misc changes


Reply
Tellos Athenaios 12:57 01-15-2011
I've identified & fixed a new problem with the tool: the ScriptRunner component would kill its host shell too soon meaning that the exit code of the program could be 0 (indicating no errors) even if errors did occur. This is sufficiently serious for me to release a new version of the tool.

This update also contains a few other changes to the tool. The main ones involve the Shell and they are: fork always expects a boolean argument to accompany the CallBack argument (it indicates whether it the CallBack must run in the same thread as the shell on which you call fork), and there is a blockUntilExit method now if you need to block a Shell until another one exits.

Reply
Tellos Athenaios 04:40 06-25-2011
The tool has not seen major action over the past few months but it did accumulate a few useful fixes so I'm calling it a release:

Bugs


Misc


Reply
Tellos Athenaios 00:02 12-07-2011
Another release with some more fixes and a few changes in behaviour.

Bugs:


Features


Misc


Reply
Tellos Athenaios 22:51 12-10-2011
Bug fix release, after a report on the TWC:

Fixes


Reply
Tellos Athenaios 23:16 09-16-2012
Almost a year on the CUF tool has accumulated a fair few bug fixes. This release contains:

Fixes


Feature


Misc


Reply
Tellos Athenaios 05:48 12-30-2012
Minor update:

Tweaked project.properties file so the project builds with Java 7 right away, without need for head scratching. (Culprit: -Xlint:depreciation.)
Binary only release now contains the Unit tests (and related auxiliary code) by default. This is part of the ground work needed for releasing another tool.

Reply
Up
Single Sign On provided by vBSSO