Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Create drawing tests for Core Text#1503

Merged
aballway merged 5 commits into
microsoft:developfrom
aballway:tests
Dec 7, 2016
Merged

Create drawing tests for Core Text#1503
aballway merged 5 commits into
microsoft:developfrom
aballway:tests

Conversation

@aballway

@aballway aballway commented Dec 2, 2016

Copy link
Copy Markdown
Contributor

Cherry picks @DHowett-MSFT's framework for image comparison tests and adds several tests for supported Core Text draw methods and options. Fixes small issues found when comparing against reference platform results and when using custom fonts, but now compares against images generated by our platform for pixel comparison. All differences between our platform and the reference platform are documented in #1502.


This change is Reviewable

#include <memory>

#include <CoreFoundation/CoreFoundation.h>
#include <UIKit/UIKit.h>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef WINOBJC
// NOTE or whatever
#import <UIKit/UIKit.h>
static void anchorUIKit() { [UIView class]; }
#endif

DHowett and others added 4 commits December 5, 2016 09:59
This change set introduces DRAW_TEST and DRAW_TEST_F, as well as a handful of
image drawing test fixtures. Commands rendered to a test's context as part of
its test body will be rasterized and saved in a file named
TestImage.$TESTCASE.$TESTNAME.png

The test driver's ideal interface is multi-modal; it needs to be able to
generate a corpus of reference images on disk, and it needs to be able to diff
them. For this, it needs a custom EntryPoint (included), and the ability to
parse command-line arguments.

The ideal default mode will be one that loads reference images from disk and
fails tests if a number of pixels differ. That work is not yet complete.

Hopefully, the draw tests here will be able to be plugged into another module
that can perhaps render them to screen, or display them as part of a UI-driven
flow for comparison and demoing purposes.

Refs microsoft#1271.
…t failure. (microsoft#1438)

CoreGraphics.Drawing.UnitTests can now be invoked in one of two modes, mediated by command line flags:

* `--compare[=/path/to/reference/folder]` (_default mode_) compare all rendered images against their baselines, failing the test if any images differ by even a single pixel.
* `--generate [--out=/path/to/output/directory]` generate output images only (do not run comparisons.)

A failing test will emit a brightly-colored diff image to `Greenlines.TestImage.CASE.TEST.png` in the _output directory_, and attach attributes to the gtest output XML data specifying where to find the images. A compatible test runner can load these images and display them side-by-side.

**Open Questions/Concerns**
* I do not like the design of `rgba/bgraPixels`.
* I do not take stride into account; if the image is width-padded, the tests will ikely fail.
* The reference platform loads images in RGBA, and we load them in BGRA. This is not an incompatibility, but it does make manual buffer manipulation dicey.
  * The fix here is to render the image into a NEW context, but that presents a few issues of its own:
    * We must trust our DrawImage function
    * We must further validate bitmap context, and trust our bitmap context as an integral part of test execution.
* All tests will be disabled as of the merge of microsoft#1434. We can re-enable them and reintroduce reference images after build validation.

Closes microsoft#1271.
@aballway

aballway commented Dec 5, 2016

Copy link
Copy Markdown
Contributor Author

Updated tests with custom font, squashed into two commits, and rebased on top of develop

@DHowett-MSFT

Copy link
Copy Markdown

When you merge this, please make sure to use the [Merge] Option. This will make conflict resolution in the CGD2D branch easier, as the commits have been cherry-picked.

@DHowett-MSFT

Copy link
Copy Markdown

The Rebase option may work as well.

@aballway

aballway commented Dec 6, 2016

Copy link
Copy Markdown
Contributor Author

Updated to disable tests on build machines, which seem to have minor differences in text drawing. Not sure if this is worth investigating. Tests can be run by enabling disabled tests

</ProjectReference>
<ProjectReference Include="..\..\..\WinObjCRT\dll\WinObjCRT.vcxproj">
<Project>{585b4870-0d6b-43a6-8e7e-ad08f7f507b6}</Project>
</ProjectReference>

@ms-jihua ms-jihua Dec 6, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't gotten to the rest of the review yet but right now i'm skeptical that you need this? #Closed

@aballway aballway Dec 6, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vcxproj or this reference? #ByDesign

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reference


In reply to: 91159582 [](ancestors = 91159582)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently required for SmartTypes #ByDesign


In reply to: 91159703 [](ancestors = 91159703,91159582)

uint32_t unusedIndex;
RETURN_IF_FAILED(_userCreatedFontCollection->FindFamilyName(fontFamilyName, &unusedIndex, &userCreatedFont));
if (userCreatedFont) {
return dwriteFactory->CreateTextFormat(fontFamilyName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah geez i need to think about this in the context of my CR, but, is this actually needed? shouldn't usercreatedfontcollection have been registered to the factory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's registered but this only uses the given font collection, or system font collection if nullptr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grrr


In reply to: 91159166 [](ancestors = 91159166)

Comment thread Frameworks/CoreText/CTFrame.mm Outdated
CGContextScaleCTM(ctx, 1.0f, -1.0f);

for (size_t i = 0; i < frame->_lineOrigins.size(); ++i) {
for (size_t i = 0; i < frame->_lineOrigins.size() && frame->_lineOrigins[i].y < frame->_frameRect.size.height; ++i) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: parens

// Forces run breaks without interfering with any layout features
// Necessary for attributes which DWrite does not support during layout (e.g. Color)
RETURN_NULL_IF_FAILED(typography->AddFontFeature({ DWRITE_FONT_FEATURE_TAG_KERNING, ++incompatibleAttributeFlag }));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self to incorporate this for my CR if this gets in first

#endif

#ifndef MAX_PATH
#define MAX_PATH PATH_MAX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

er, any reason why we can't just standardize on the underscore version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @DHowett-MSFT said underscoreless is standard?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah: MAX_PATH lives in minwindef standalone and _MAX_PATH lives in stdlib with proximity to the standard library path functions.

CGBlendMode blendMode;
};

CGNamedBlendMode porterDuffBlendModes[] =

@ms-jihua ms-jihua Dec 6, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static const, c_
same for your other constants below #WontFix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will leave the CG* tests for @DHowett-MSFT to clean up :D

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O7

@@ -0,0 +1,105 @@
//******************************************************************************

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has a lot of duplicated code. Can you refactor it into reusable functions or parameterized tests?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take this on as I wrote this code. I'm hoping to reduce merge conflicts from develop in the meantime.

@@ -0,0 +1,52 @@
//******************************************************************************

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this file, to a lesser extent

CFStringRef keys[2] = { kCTFontAttributeName, kCTParagraphStyleAttributeName };
CFTypeRef values[2] = { myCFFont.get(), paragraphStyle.get() };

woc::unique_cf<CFDictionaryRef> dict{ CFDictionaryCreate(nullptr,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably refactor 389-403 here to a separate function, possibly 403-416 as well (would exclude CTRun, BasicDrawingTest, WhiteBackgroundTest though)

}

CFStringRef _CFStringCreateAbsolutePath(CFStringRef relativePath) {
std::unique_ptr<char[]> owningFilenamePtr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

85-101 here is repeated from above

@ms-jihua

ms-jihua commented Dec 6, 2016

Copy link
Copy Markdown
Contributor

nit: CoreGraphics.Drawing > CoreGraphics.drawing, probably

@ms-jihua

ms-jihua commented Dec 6, 2016

Copy link
Copy Markdown
Contributor

🕐

@DHowett-MSFT

Copy link
Copy Markdown

:shipit:

@ms-jihua ms-jihua left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline - in the interest of ease of merging with CGD2D, code quality-related comments will be taken care of separately at a later time by @DHowett-MSFT

@aballway

aballway commented Dec 6, 2016

Copy link
Copy Markdown
Contributor Author

Updated with changes to CTDrawingTests

@DHowett-MSFT

Copy link
Copy Markdown

:shipit:

@aballway aballway merged commit 502794e into microsoft:develop Dec 7, 2016
@aballway aballway deleted the tests branch January 12, 2017 18:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants