Coordinate System in Windows GDI (1)

Source: Internet
Author: User

Coordinate System in Windows GDI (1)

By leezy_2000

 

If you have output text, bitmap, or drawn a line or curve, you must have used a coordinate system. The screen resolution is 96 DPI (DOT per inch), and the printer resolution is usually 600 dpi.

Movable ETO (HDC, 100,100 );

Lineto (HDC, 1300,1300 );

The two lines above the two may generate exactly the same (WYSIWYG ). In terms of implementation principle, the coordinate system plays a decisive role in it.

 

1. What is the GDI coordinate system?

 

First of all, from the mathematical point of view, the GDI coordinate system is a two-dimensional Cartesian coordinate system. The position of any point on the plane can be determined through two axes and the origin.

From the perspective of usage, the GDI coordinate system is a conversion rule that converts the logic data you have developed into the data that can be used by the final device driver. For example (100,100), after the actual change, the screen on 96 DPI may be (9.6, 9.6), and the printer on DPI may be (60, 60 ). (Note 1)

The GDI coordinate system consists of four-layer coordinate spaces (note 2). the levels are as follows:

 

World-space ):Supports affine transformation, which is applied to the page coordinate space mentioned below and only supported in NT operating systems.

 

Page coordinate space ):Supports a large number of predefined ing modes, which is the coordinate space that will inevitably be used. The origin and the corresponding scaling ratio are suitable for setting in the page coordinate space.

 

The world coordinate space and page coordinate space are collectively referred to as the logical coordinate space, which can be directly used by the GDI user. That is to say, the position, size, and other information you specify can only be the data relative to the logical coordinate space during the GDI output.

 

Device-space ):The device space associated with the device context. A small block of a physical device or an entire physical device. Because the various GDI outputs are oriented to the device context, the data in the logical coordinate space must naturally be converted into the data in the device coordinate space.

 

Physical-device space ):Part or whole of the physical surface of the graphic device. That is, the coordinate space used by the graphic driver. Any GDI output will eventually be formed on the display or printer through the relevant driver, and the conversion from the device coordinate space to the physical device coordinate space becomes a necessity. This process is completely completed by the system. Therefore, the DC origin and size are read-only. (For convenience, the following uses DC to represent the device context)

 

2. Where is the output location?

 

From the preceding instructions, we can see that the final output position must be changed at least twice (If you enable the world coordinate space, it would be three times ), is there any way to directly determine which physical location the logical point will eventually correspond? It is not complicated to implement one by ourselves. First, we need to convert the logical coordinates into the device coordinates. This process requires a lot of operations based on the affine matrix and the current ing mode, but we do not perform this operation ourselves, but use

BOOL LPtoDP( 

 HDC hdc,           // handle to device context

   LPPOINT lpPoints// array of points

   int nCount         // count of points in array

);

This function is responsibleLppointsThe logical coordinate transformation in is the device coordinate associated with HDC. (We will complete this function ourselves later ).

Because the device coordinates are the same as those of physical devices, they are all physical device points. Therefore, converting device coordinates to physical device coordinates is not so troublesome, you only need to know the DC origin (note that the origin here refers to the location of the device coordinate space's origin in the physical device coordinate space ). The essence of this task is to read the dc structure of the OS. We use

BOOL GetDCOrgEx(

  HDC hdc,          // handle to a DC

  LPPOINT lpPoint   // translation origin

);

To complete this task.

In this case, for any logical point logicalpoint, the DC origin is dcorgpoint:


Physicaldevicepoint is the location of the logicalpoint in the coordinate space of the physical device theoretically. It must be noted that because the coordinate space of a physical device does not necessarily cover the entire physical surface of a graphic device, the location calculated from physicaldevicepoint is not necessarily the location on the physical surface. For example, the actual position is to add four or more areas that cannot be printed. At the same time, physical devices such as monitors must also consider whether physical devices are scaled. If not (that is, the buttons below the displays are useless) then you will find that the size we calculated matches well with the corresponding position on the screen.

 

Void getphysicalposition (HDC, lppoint, int ncount) is used to complete the above functions. For specific implementation, see Source Code 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.