// format page size according to locale (e.g. "29.7 x 21.0 cm" or "11.69 x 8.27 in") // Caller needs to free the result static WCHAR *FormatPageSize(BaseEngine *engine, int pageNo, int rotation) { RectD mediabox = engine->PageMediabox(pageNo); SizeD size = engine->Transform(mediabox, pageNo, 1.0f / engine->GetFileDPI(), rotation).Size(); const WCHAR *formatName = L""; switch (GetPaperFormat(size)) { case Paper_A4: formatName = L" (A4)"; break; case Paper_A3: formatName = L" (A3)"; break; case Paper_A5: formatName = L" (A5)"; break; case Paper_Letter: formatName = L" (Letter)"; break; case Paper_Legal: formatName = L" (Legal)"; break; case Paper_Tabloid: formatName = L" (Tabloid)"; break; case Paper_Statement: formatName = L" (Statement)"; break; } bool isMetric = GetMeasurementSystem() == 0; double unitsPerInch = isMetric ? 2.54 : 1.0; const WCHAR *unit = isMetric ? L"cm" : L"in"; double width = size.dx * unitsPerInch; double height = size.dy * unitsPerInch; if (((int)(width * 100)) % 100 == 99) width += 0.01; if (((int)(height * 100)) % 100 == 99) height += 0.01; ScopedMem<WCHAR> strWidth(str::FormatFloatWithThousandSep(width)); ScopedMem<WCHAR> strHeight(str::FormatFloatWithThousandSep(height)); return str::Format(L"%s x %s %s%s", strWidth.Get(), strHeight.Get(), unit, formatName); }
// format page size according to locale (e.g. "29.7 x 21.0 cm" or "11.69 x 8.27 in") // Caller needs to free the result static WCHAR *FormatPageSize(BaseEngine *engine, int pageNo, int rotation) { RectD mediabox = engine->PageMediabox(pageNo); SizeD size = engine->Transform(mediabox, pageNo, 1.0f / engine->GetFileDPI(), rotation).Size(); const WCHAR *formatName = L""; SizeD sizeP = size.dx < size.dy ? size : SizeD(size.dy, size.dx); // common ISO 216 formats (metric) if (limitValue(sizeP.dx, 8.26, 8.28) == sizeP.dx && limitValue(sizeP.dy, 11.68, 11.70) == sizeP.dy) formatName = L" (A4)"; else if (limitValue(sizeP.dx, 11.68, 11.70) == sizeP.dx && limitValue(sizeP.dy, 16.53, 16.55) == sizeP.dy) formatName = L" (A3)"; else if (limitValue(sizeP.dx, 5.82, 5.85) == sizeP.dx && limitValue(sizeP.dy, 8.26, 8.28) == sizeP.dy) formatName = L" (A5)"; // common US/ANSI formats (imperial) else if (limitValue(sizeP.dx, 8.49, 8.51) == sizeP.dx && limitValue(sizeP.dy, 10.99, 11.01) == sizeP.dy) formatName = L" (Letter)"; else if (limitValue(sizeP.dx, 8.49, 8.51) == sizeP.dx && limitValue(sizeP.dy, 13.99, 14.01) == sizeP.dy) formatName = L" (Legal)"; else if (limitValue(sizeP.dx, 10.99, 11.01) == sizeP.dx && limitValue(sizeP.dy, 16.99, 17.01) == sizeP.dy) formatName = L" (Tabloid)"; WCHAR unitSystem[2]; GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, unitSystem, dimof(unitSystem)); bool isMetric = unitSystem[0] == '0'; double unitsPerInch = isMetric ? 2.54 : 1.0; const WCHAR *unit = isMetric ? L"cm" : L"in"; double width = size.dx * unitsPerInch; double height = size.dy * unitsPerInch; if (((int)(width * 100)) % 100 == 99) width += 0.01; if (((int)(height * 100)) % 100 == 99) height += 0.01; ScopedMem<WCHAR> strWidth(str::FormatFloatWithThousandSep(width)); ScopedMem<WCHAR> strHeight(str::FormatFloatWithThousandSep(height)); return str::Format(L"%s x %s %s%s", strWidth, strHeight, unit, formatName); }
// format page size according to locale (e.g. "29.7 x 20.9 cm" or "11.69 x 8.23 in") // Caller needs to free the result static WCHAR *FormatPageSize(BaseEngine *engine, int pageNo, int rotation) { RectD mediabox = engine->PageMediabox(pageNo); SizeD size = engine->Transform(mediabox, pageNo, 1.0, rotation).Size(); WCHAR unitSystem[2]; GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, unitSystem, dimof(unitSystem)); bool isMetric = unitSystem[0] == '0'; double unitsPerInch = isMetric ? 2.54 : 1.0; double width = size.dx * unitsPerInch / engine->GetFileDPI(); double height = size.dy * unitsPerInch / engine->GetFileDPI(); if (((int)(width * 100)) % 100 == 99) width += 0.01; if (((int)(height * 100)) % 100 == 99) height += 0.01; ScopedMem<WCHAR> strWidth(str::FormatFloatWithThousandSep(width)); ScopedMem<WCHAR> strHeight(str::FormatFloatWithThousandSep(height)); return str::Format(L"%s x %s %s", strWidth, strHeight, isMetric ? L"cm" : L"in"); }