Printer C + +

Source: Internet
Author: User

M_prndc.setmapmode (Mm_lometric);
M_IPRNX = M_prndc.getdevicecaps (horzres);
M_iprny = M_prndc.getdevicecaps (vertres);
The M_IPRNX is wide and the M_iprny is high.

Gets the horizontal and vertical resolution of the printer device
Pixel points per inch
int xpixperinch = Pdc->getdevicecaps (LOGPIXELSX);
int ypixperinch = Pdc->getdevicecaps (Logpixelsy);
If the PDC is a printer DC, then Xpixperinch =ypixperinch =600
If the PDC is a screen DC, then Xpixperinch =ypixperinch =96

Cdc::setmapmode

virtual int setmapmode (int nmapmode );

Function Description: This function sets the mapping method for the specified device environment, which defines the unit of measure to convert the logical units to device units and defines the direction of the X and Y axes of the device.

Nmapmode: Specifies the new mapping method, which can be any one of the values listed below.

  Mm_anisotropic: Logical units are converted to any unit with arbitrary proportional axes, with Setwindowextex and Setviewportextex functions to specify units, orientations, and proportions.

  Mm_hienglish: Each logical unit is converted to 0.001 inch, the Square of the X is oriented to the right, andY to the square upward.

mm_himetric : Convert each logical unit to 0.01 mm, x positive direction right, y

mm_isotropic : Logical units are converted to any unit with an equal proportional axis, i.e. along xygdix< Span style= "color:black;" > and y units remain the same size (when setting the window range, < Span style= "color: #3366cc;" > viewport will be adjusted to achieve the same unit size).

  Mm_loenglish: Convert each logical unit to 0.1 inch,X positive direction to the right andY positive direction upward.

  Mm_lometric: Converts each logical unit to 0.1 mm,X positive direction to the right, andY positive direction upward.

  Mm_text: Each logical unit is converted to a single voxel, theX is in the right direction and theY direction is downward.

Mm_twips,each logical unit is converted to 1 of the print point (i.e. 1/1400 inch),X positive direction to the right,Y Direction upward.

Note:

The Mm_text mode allows applications to work in device pixels, and the size of the pixel varies depending on the device. mm_hienlish, Mm_himetric, Mm_loenglish, Mm_lometric, and mm_twips methods are useful for applications that must be mapped in physical units of meaning, such as inches or millimeters. The Mm_isotropic method guarantees a 1:1 aspect ratio. The Mm_hienlish mode allows the X and Y coordinates to be adjusted separately.


by habit, (0,0) on the origin, the origin is (0,0), but if you use this to understand the Windows Map mode, will be detours. In fact, a little change of concept, the Windows Map mode is better understood. To illustrate:

Page space---->device space
Pdc->setmapmode (Mm_lometric);
Pdc->setwindoworg (40,0); This "set" page space is the origin (40,0), note that
At this time (40,0) is the origin point, the origin is (40,0) this point, in fact, (0,0) and the origin is not necessarily linked. This
There is no effect on the diagram in page space of the following drawing function. Sentence: setwindoworg
is to specify which point in page space is the origin point.
Pdc->rectangle (0,0,100,-100);
Pdc->rectangle (0,-100,50,-200);

Similarly, setviewportorg is also specified, which point in device space is the origin point,When two coordinate system mappings, the two Origin points coincide.

SetWindowExt set the size of page space, setviewportorg set the size of device space, in fact, really meaningful is only the proportional relationship between the two, for example, on a 1024x768 display:

Pdc->setmapmode (Mm_isotropic);
Pdc->setwindowext (10240,7680);
Pdc->setviewportext (1024,768);
Pdc->rectangle (0,0,100,100);//The logical unit is given, but the specific drawing to be converted into device units, the conversion ratio determined by the pattern

You will draw a rectangle with a pixels of ten pixels*10. the essence is, x direction, each logical unit has 1024/10240 pixels, y direction each logical unit has 768/7680 pixels. Therefore, the following code has the same effect:

Pdc->setmapmode (Mm_isotropic);
Pdc->setwindowext (102400,76800);
Pdc->setviewportext (10240,7680);
Pdc->rectangle (0,0,100,100);

The two are essentially the same, and the former is easier to understand.
================================

SetWindowOrg and setviewportorg These two functions are difficult to understand, after my Google and practice finally figured out the essential difference between the two functions.

1.SetWindowOrg (x, y) is the mapping of the origin (viewport) of the device coordinates to the logical coordinates (x, y)

2.SetViewportOrg (x, y) maps the origin (window) of the logical coordinates to the device coordinates (x, y)

3. The device origin is always the top-left vertex of the client area (upper the corner of the client region).

(A later figure shows the meaning of the two functions)
Note the difference between device coordinates and logical coordinates:

1. Device coordinates x, Y axis direction is fixed, the unit is fixed, the x-axis increases to the right, and y down increments, units are pixels.

2. Logical coordinates x, Y axis direction is not fixed, the unit is not fixed, according to the selected mapping mode and change.

With the above explanations, I believe you should be able to understand why the actual results of the following code will be the case.

void Cex05aview::ondraw (cdc* pDC)
{
Pdc->setmapmode (Mm_lometric);
pdc->setwindoworg (100, 100);
Pdc->rectangle (0, 0, 200, 200);

pdc->setviewportorg (100, 100);
Pdc->selectstockobject (Gray_brush);
Pdc->rectangle (0, 0, 200, 200);
}

====================================================

The establishment of a suitable coordinate system can bring great convenience to our drawing. Here's how to build the coordinate system we want in VC.
a device coordinate and a logical coordinate
   Device coordinate, also known asPhysical coordinates (physical coordinate) refer to the coordinates on the output device. Usually the device coordinates on the screen are calledScreen coordinates. Device coordinates specify the position of the object by the horizontal distance and vertical distance of the object from the upper-left corner of the window, which isExpressed in pixels, the x-axis of the device coordinates is positive, the y-axis is positive, and the coordinate origin is in the upper-left corner of the window.
   Logical coordinates (Logical coordinate) are the coordinates that the system uses as records. In the default mode (Mm_text), the direction and units of the logical coordinates are the same as the direction and units of the device coordinates, are expressed in pixels, the x-axis is positive, the y-axis is positive, and the coordinate origin is in the upper-left corner of the window. Logical and device coordinates even in the default mode, their values may not be the same, except in the following two cases:
1. Window is not a scrolling window
2. The window is a scrolling window, but the vertical scrollbar is at the top of the scroll border and the horizontal scroll bar is at the leftmost end, but if you move the scroll bar, the coordinates are inconsistent.
In the VC, the coordinates of the mouse coordinates are represented in device coordinates, but all GDI plots are represented in logical coordinates, so when drawing with the mouse, the device coordinates must be converted to logical coordinates, and you can use the CDC function Dptolp () to convert device coordinates to logical coordinates. You can also use LPTODP () to convert logical coordinates into device coordinates.

two coordinate mode
To use logical coordinates in different domains, Windows provides the following 8 coordinate modes:
Mm_text, Mm_hienglish, Mm_loenglish, Mm_himetric, Mm_lometric, Mm_twips, Mm_anisotropic and Mm_isotropic, respectively.

Three example parsing
(a) establish the coordinates with the upper-left corner as the origin, the x-axis and the y-axis 1000, as
We can use the following code:
void Cttview::ondraw (cdc* pDC)
{
cttdoc* PDoc = GetDocument ();
Assert_valid (PDOC);
CRect rect;
GetClientRect (&rect);

Pdc->setmapmode (Mm_anisotropic);
Pdc->setviewportorg (0,0);
Pdc->setviewportext (Rect.right,rect.bottom);

Pdc->setwindoworg (0,0);
Pdc->setwindowext (1000,1000);

Pdc->moveto (50,50);
Pdc->lineto (50,950);
Pdc->lineto (950,950);
Pdc->lineto (50,50);
}
Code Analysis:
1. GetClientRect (&rect); Obtain a rectangular area of the customer area, storing it in a rect
2. Using Pdc->setmapmode (MM_ANISOTROPIC); Set mapping mode
3. Pass pdc->setviewportorg (0,0); Set the origin of the logical coordinates.
4. Adoption of Pdc->setviewportext (Rect.right,rect.bottom);
Pdc->setwindowext (1000,1000); To determine the dimension correspondence between the logical coordinates and the device coordinates
5. In mm_anisotropic mode, the x-axis units and y-axis units can be different
6. The coordinate direction is determined if the logical and viewport range symbols are the same, then the direction of the logical coordinates is the same as the direction of the viewport, that is, the x-axis is positive to the right and the y-axis is positive.
7. If the display mode is changed to Mm_isotropic, then the x-axis units and y-axis units must be the same, and interested readers can make their own.
(b) Establish coordinates with the window center as the origin, as follows:
Use the following code:
void Cttview::ondraw (cdc* pDC)
{
cttdoc* PDoc = GetDocument ();
Assert_valid (PDOC);
CRect rect;
GetClientRect (&rect);

Pdc->setmapmode (Mm_anisotropic);
Pdc->setviewportorg (RECT.RIGHT/2,RECT.BOTTOM/2);
Pdc->setviewportext (Rect.right,rect.bottom);

Pdc->setwindoworg (0,0);
Pdc->setwindowext (1000,-1000);

Pdc->moveto (150,150);
Pdc->lineto ( -150,-200);
Pdc->lineto (150,-150);
Pdc->lineto (150,150);
}
Code Analysis:
1. Using pdc->setviewportorg (RECT.RIGHT/2,RECT.BOTTOM/2); Sets the origin point of the viewport.
2. Use Pdc->setviewportext (Rect.right,rect.bottom), and Pdc->setwindowext (1000,-1000) to determine the unit correspondence of the device coordinates and the logical coordinates.
3. Because the symbol of the logical window range and viewport range is inconsistent, the ordinate is reversed, so the y-axis is positive.

Mm_loenglish, Mm_hienglish, Mm_lometric, Mm_himetric, mm_twips This group is an important fixed-scale mapping model provided by Windows.

They are all X-values increasing to the right, and the Y-values decreasing downward and cannot be changed. The difference between them is that the scale factor is the following: (I think the P53 page in the book must have been printed incorrectly, as the X-value is incremented by the program experiment)

Mm_loenglish 0.01 inch
Mm_hienglish 0.001 inch
Mm_lometric 0.1mm
Mm_himetric 0.01mm
Mm_twips 1/1440 in.//applied to the printer, a twip equivalent to 1/20 pounds and a pound equal to 1/72 inches.

Printer C + +

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.