Commit Graph

1973 Commits

Author SHA1 Message Date
David Wendt 670c4723e3 Add support for the `kerning` flag, which turns on and off the kerning information on fonts. 2020-06-20 19:55:53 -04:00
David Wendt 3c9a43ea72 Add a regression test for newlines.
This test includes tests for HTML newlines, which causes the XML parser in Ruffle to throw errors. Hence why it's currently ignored.
2020-06-20 19:55:53 -04:00
David Wendt 180ef3b423 Recognize `<br>` as a line break.
This code is currently unreachable as `<br>` will actually trigger an AVM1 error due to our overly-strict XML parser.
2020-06-20 19:55:52 -04:00
David Wendt 045a81e79e Implement `html` and `htmlText`... sort of.
There are several problems, first off:

1. I'm not entirely sure what I'm supposed to be changing on the text field when someone writes `html`.
2. We're using the XML parser for HTML (both `htmlText` and SWF tag parsing) which causes problems. Notably, `<br>` issues an AVM1 error (!!!) because the XML parser doesn't like unclosed tags.
3. Reading `htmlText` should not return the same HTML tree (at least, not until we implement stylesheets). It should instead regenerate an HTML tree from text spans.
2020-06-20 19:55:52 -04:00
David Wendt 2452124631 Break individual words at the start of lines that are too big to fit on the line. 2020-06-20 19:55:51 -04:00
David Wendt 6c44418b10 Add a test for tab_stops.
This test is currently inaccurate by up to 5 pixels, this is due to some behavior with really, really wide tabstops and word breaks that I don't entirely get yet.
2020-06-20 19:55:51 -04:00
David Wendt 2ad216cab4 Don't continue comparing tab stops after we find one that fits. 2020-06-20 19:55:50 -04:00
David Wendt b6c12b1e23 Use current font height times 2.7 as the natural tab stop, as that seems to match Flash... for now. 2020-06-20 19:55:50 -04:00
David Wendt 0e45dc12e9 Recompile the letter spacing test 'cause I spotted an errant `s` in the FLA 2020-06-20 19:55:49 -04:00
David Wendt 2caaa6875d Add support for explicit tabs and newlines. 2020-06-20 19:55:49 -04:00
David Wendt 153ab675e9 When aligning a line, actually consider all the boxes within the line. 2020-06-20 19:55:49 -04:00
David Wendt 3d094ed689 Add margins test.
This test is also approx'd to 1px due to the same issue where heights are off by one.
2020-06-20 19:55:48 -04:00
David Wendt db0398d2ee Left and right margins and indents should not be included in `textWidth`. 2020-06-20 19:55:48 -04:00
David Wendt 74d4c25133 Add a test for letter spacing.
This test is approximate because the 0.5px test is off by 1px in terms of height.
2020-06-20 19:55:47 -04:00
David Wendt 6ce7ecee78 Implement `letterSpacing`. 2020-06-20 19:55:47 -04:00
David Wendt 171954d5e4 Add `edittext_leading` test.
This test constructs a handful of text fields and measures them. Each field has 0, 5, or 15px of `leading` applied to it's text format.
2020-06-20 19:55:47 -04:00
David Wendt bbc73f1477 The `edittext_align` test now passes perfectly. 2020-06-20 19:55:46 -04:00
David Wendt 16da6d827c Line-leading is always applied at least once, even if there are no line breaks in the text field. 2020-06-20 19:55:46 -04:00
David Wendt 410fb3ab86 Don't round each line's leading. Instead, round at the end of the operation.
This was verified by visual comparison with Flash Player; lines of text appear to be shifted by half-pixels, while the script output is always still rounded down.
2020-06-20 19:55:45 -04:00
David Wendt 2858c09b6e Only apply leading adjustment on newlines.
This results in ALL height adjustments being off by 2px, regardless of leading or font size. Tantalizing!
2020-06-20 19:55:45 -04:00
David Wendt 2ab85c32e2 When wrapping text, measure the text including the trailing space (if present).
This matches Flash behavior, but breaks an existing test, which I've adjusted appropriately.
2020-06-20 19:55:44 -04:00
David Wendt c67bf0b6b7 Add approximate test of text field metrics during alignment.
This is an approximate text with a 1-pixel tolerance because our height is currently off by one and I cannot explain why. Previous attempts to fix the bug have resulted in cascading errors that resulted in off-by-one errors in the opposite direction. This is still better than nothing and I need to check other tests in.
2020-06-20 19:55:44 -04:00
David Wendt a1e52ab556 Add a test for formatting defaults on HTML text. 2020-06-20 19:55:44 -04:00
David Wendt 09c91d191a Round-trip tab stops between `EditText` and AVM1 2020-06-20 19:55:43 -04:00
David Wendt 00217072e6 After the previous set of fixes our tests are now consistent with a layout engine that always rounds down to the nearest pixel and never up. Adjust code to match. 2020-06-20 19:55:43 -04:00
David Wendt 06c66533c7 Don't apply leading twice. 2020-06-20 19:55:42 -04:00
David Wendt 82c6269cf6 Ensure that presentational markup styles cascade from parent tag to child, and from the default format to the first tag. 2020-06-20 19:55:42 -04:00
David Wendt 88d07f5d17 We don't need to relayout when the new-text text format gets changed. 2020-06-20 19:55:42 -04:00
David Wendt 9981148482 Add a test for `BoxBounds.with_size`, since we're using it now 2020-06-20 19:55:41 -04:00
David Wendt aae1f0ba7a Skip fixups on empty lines. 2020-06-20 19:55:41 -04:00
David Wendt bd40295076 Ensure that the font-provided leading is accounted for when moving the cursor for a newline. 2020-06-20 19:55:41 -04:00
David Wendt 0e0b2fb85d All layout boxes on the line should have trailing whitespace trimmed off of their measurements.
Flash has a weird bug where it will NOT trim trailing spaces off of the metrics reported to users if the text is left-aligned. We replicate this here so that tests pass.
2020-06-20 19:55:40 -04:00
David Wendt 50a05df998 Generated lines should *always* include their end spaces, there should be no gaps. 2020-06-20 19:55:40 -04:00
David Wendt ab2b9cc733 Change all of the `BoxBounds` in the layout machinery to not use `Default`.
The `Default` bounds are NOT safe to union against if they were uninitialized. Doing so will force any resulting layout box to enclose `(0,0)`, which can throw off certain layout calculations. Instead, we use `None` to signal an uninitialized box.
2020-06-20 19:55:40 -04:00
David Wendt 806a741bf4 EditText appears to have internal padding between it's borders equivalent to a CSS padding of `3px 4px 3px 0`.
Verified by experimentation with Flash Player, appears to be necessary for tests to pass.
2020-06-20 19:55:39 -04:00
David Wendt 96c43654d0 Retain the bounds returned when constructing layout boxes and use them as the `textWidth` and `textHeight` of a given text field. 2020-06-20 19:55:39 -04:00
David Wendt 318f09d241 Include the font-provided leading in the exterior bounds sent off for `autoSize` calculation. 2020-06-20 19:55:39 -04:00
David Wendt 06dc2f5fe0 Implement the `leading` attribute as defined by fonts.
`EditText` supports two different forms of leading:

1. Font-provided leading, specified relative to the EM square and scaled with font size
2. User-specificed leading, specified in pixels

Notably, the former appears to apply to the first line in the text and pushes it down. This showed up in the `edittext_font_size` test, and according to that test result the leading is rounded *up* to the nearest pixel, plus one.

That last bit seems possibly wrong and is subject to further change, but it matches the tests at multiple scales.
2020-06-20 19:55:29 -04:00
David Wendt 6e81f30a70 Round down to the nearest pixel when measuring text.
Certain text routines calculate text on the pixel grid, despite the fact that Flash ordinarily works in twips. There is probably a reason for this - my guess is to keep text wrapping stable across multiple pixel densities (e.g. low-res screens plus high-res print).
2020-06-20 19:53:42 -04:00
David Wendt 7a62a8e9ce Programmatically created text fields get a biased depth. 2020-06-20 19:53:34 -04:00
David Wendt 75aaa49169 Y coordinates should always be adjusted by Y coordinates. 2020-06-20 19:48:14 -04:00
David Wendt 245cea784f Running an `autoSize` on any text field should always synchronize the X coordinate between the bounding box and the base transform.
I don't know why, but this is necessary for the "NEW STUFF" box on homestarrunner.com's toons menu to position correctly. SOMEWHERE, we are performing some kind of operation that adjusts one of the two, but not the other, and I can't find out what.
2020-06-20 19:48:13 -04:00
David Wendt 5a2b74c5fc Setting a new matrix should also transform the bounds as well. 2020-06-20 19:48:13 -04:00
David Wendt e7e944ad76 Account for the width of glyphs when measuring text.
This fixes spaces at the start of text spans not being rendered, but also breaks center-align.

I also broke the font tests, so I had to rewrite them, which makes me question their value.
2020-06-20 19:48:13 -04:00
David Wendt 8a5a2bf7c7 When `Font.wrap_text` indicates that none of the line can fit, we should also refresh our width and offset and check if there's even more text to measure or not. 2020-06-20 19:48:12 -04:00
David Wendt efc50da367 `Font.wrap_text` should return `0` if no part of the string can fit within the requested bounds. 2020-06-20 19:48:12 -04:00
David Wendt 38d679ef29 `wrap_line` should take spaces into account when sizing lines. 2020-06-20 19:48:12 -04:00
David Wendt 85a3a845d9 Dynamic `EditText` bounds should go from `x` to `x+width`, not `x` to `x+height` (etc) 2020-06-20 19:48:12 -04:00
David Wendt bacbf06614 Setting the matrix of an `EditText` should scale it's bounds. 2020-06-20 19:48:12 -04:00
David Wendt 9564cbeda4 Use the new dynamic bounding box to calculate a width for word-wrapping, and update the new bounding box directly in autosize rather than hitting `DisplayObject` methods.
This also adjusts `DisplayObject` methods to use the bounds.
2020-06-20 19:48:11 -04:00