TypesettingCartel/ASSInspector — pull request #10 by torque (2014-10-16 07:45:14+00:00)
Title: Massive Library Restructuring.

Okay, so after claiming I didn't have time to work on this, I had a discussion with line0, and got fixated on a stupid idea, that I decided to implement. So I implemented it. And now I'd like to talk about it.

**disclaimer**: I am not necessarily suggesting merging this pull request wholesale into master as it contains a lot of changes, some of which may be controversial or bad.

#### The idea

Initially, the plan was to hack in bounding box calculation which, while somewhat more rigorous than simply checking for a dirty rect, is also far more useful.

#### Highlights

##### Events are no longer stored in the library

After that long discussion about the best way to store events, and talking to @line0 about it, I realized there wasn't even really a good reason to actually store events.

Initially implemented in 18b8f68, `assi_setScript` takes two strings as input (one optionally NULL) and generates a minimal script with it. Note that the script header is still stored on library init, as it is unlikely to change in between runs.

##### Error strings can now be accessed

`const char* assi_getErrorString( ASSI_State* )` was added in 3d84636, allowing users to actually access the error string. Additionally, a few internal errors actually set the error string properly.

##### A well-commented example script has been added

OptimASS aside, the easiest way to test the API and document it simultaneously was to write an example for how it is intended to be used. Note that the example is Aegisub-specific, but should be usable by anyone.

##### Font management

As of e696a84, it is possible for the user to specify a directory that fontconfig should search for fonts. This provides a convenient alternative to fontconfig taking time to cache all of the system's fonts.

##### Uses libass's caching mechanism

c863c8f implements libass's reporting of sequential lines that are identical. This allows the bounding box to be copied (or moved) rather than having to check for it all over again.

#### Issues

##### Lots of code duplication

It seems I am incapable of both implementation and design simultaneously. Or perhaps I am just incapable of design. The loop that does bounds checking is present three times in the source, and the code for checking moved events vs checking new events is very similar.

##### Doesn't take some short cuts

Based on observation, it seems that if the width (as given by `ASS_Image->w`) is not padded to the nearest mod 16 integer (which only seems to happen if a clip is present) then the reported width is the exact dirty rect width. The same holds true for height.

However it is possible that there is some weird case that taking this shortcut would not work on.