blob: b5f6142aa921d79b1d05b6f2788c758591904d67 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2012 The Chromium Authors
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]08397d52011-02-05 01:53:385#include "ui/gfx/gdi_util.h"
initial.commitd7cae122008-07-26 21:49:386
avic89eb8d42015-12-23 08:08:187#include <stddef.h>
8
dcheng0917ec42015-11-19 07:00:209#include <algorithm>
danakj25c52c32016-04-12 21:51:0810#include <memory>
dcheng0917ec42015-11-19 07:00:2011
Tom Sepez978847c2025-03-22 03:43:5912#include "base/compiler_specific.h"
tomhudsonf0cd274b2016-07-27 14:46:1013#include "skia/ext/skia_utils_win.h"
pkasting7bc277b2014-10-13 20:58:3914
15namespace gfx {
16
danakjbdf1e0a2020-11-10 18:27:4717void CreateBitmapV4HeaderForARGB888(int width,
18 int height,
19 BITMAPV4HEADER* hdr) {
initial.commitd7cae122008-07-26 21:49:3820 // Because bmp v4 header is just an extension, we just create a v3 header and
21 // copy the bits over to the v4 header.
22 BITMAPINFOHEADER header_v3;
danakjbdf1e0a2020-11-10 18:27:4723 skia::CreateBitmapHeaderForXRGB888(width, height, &header_v3);
Tom Sepez978847c2025-03-22 03:43:5924 UNSAFE_TODO(memset(hdr, 0, sizeof(BITMAPV4HEADER)));
25 UNSAFE_TODO(memcpy(hdr, &header_v3, sizeof(BITMAPINFOHEADER)));
initial.commitd7cae122008-07-26 21:49:3826
27 // Correct the size of the header and fill in the mask values.
28 hdr->bV4Size = sizeof(BITMAPV4HEADER);
29 hdr->bV4RedMask = 0x00ff0000;
30 hdr->bV4GreenMask = 0x0000ff00;
31 hdr->bV4BlueMask = 0x000000ff;
32 hdr->bV4AlphaMask = 0xff000000;
33}
34
pkasting46a62912014-10-09 21:30:0035float CalculatePageScale(HDC dc, int page_width, int page_height) {
[email protected]1a30dd32012-01-28 00:56:4336 int dc_width = GetDeviceCaps(dc, HORZRES);
37 int dc_height = GetDeviceCaps(dc, VERTRES);
38
39 // If page fits DC - no scaling needed.
40 if (dc_width >= page_width && dc_height >= page_height)
41 return 1.0;
42
pkasting46a62912014-10-09 21:30:0043 float x_factor =
44 static_cast<float>(dc_width) / static_cast<float>(page_width);
45 float y_factor =
46 static_cast<float>(dc_height) / static_cast<float>(page_height);
[email protected]1a30dd32012-01-28 00:56:4347 return std::min(x_factor, y_factor);
48}
49
50// Apply scaling to the DC.
pkasting46a62912014-10-09 21:30:0051bool ScaleDC(HDC dc, float scale_factor) {
[email protected]1a30dd32012-01-28 00:56:4352 SetGraphicsMode(dc, GM_ADVANCED);
53 XFORM xform = {0};
54 xform.eM11 = xform.eM22 = scale_factor;
55 return !!ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
56}
57
initial.commitd7cae122008-07-26 21:49:3858} // namespace gfx