public void ImageStyles_ConvertedToPercent(string sizeClass, double pageWidthMm)
{
var book = SetupBookLong("This is some text", "en",
extraPageClass: " " + sizeClass,
extraImages: @"<div><img src='image1.png' width='334' height='220' style='width:334px; height:220px; margin-left: 34px; margin-top: 0px;'></img></div>
<div><img src='image2.png' width='330' height='220' style='width:330px; height: 220px; margin-left: 33px; margin-top: 0px;'></img></div>");
MakeImageFiles(book, "image1", "image2");
MakeEpub("output", "ImageStyles_ConvertedToPercent" + sizeClass, book);
CheckBasicsInManifest();
CheckBasicsInPage();
// A5Portrait page is 297/2 mm wide
// Percent size however is relative to containing block, typically the marginBox,
// which is inset 40mm from page
// a px in a printed book is exactly 1/96 in.
// 25.4mm.in
var marginboxInches = (pageWidthMm-40)/25.4;
var picWidthInches = 334/96.0;
var widthPercent = Math.Round(picWidthInches/marginboxInches*1000)/10;
var picIndentInches = 34/96.0;
var picIndentPercent = Math.Round(picIndentInches / marginboxInches * 1000) / 10;
AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:img[@style='width:" + widthPercent.ToString("F1")
+ "%; height:auto; margin-left: " + picIndentPercent.ToString("F1") + "%; margin-top: 0px;']", _ns);
picWidthInches = 330 / 96.0;
widthPercent = Math.Round(picWidthInches / marginboxInches * 1000) / 10;
picIndentInches = 33 / 96.0;
picIndentPercent = Math.Round(picIndentInches / marginboxInches * 1000) / 10;
AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:img[@style='width:" + widthPercent.ToString("F1")
+ "%; height:auto; margin-left: " + picIndentPercent.ToString("F1") + "%; margin-top: 0px;']", _ns);
}