Skip to Content

What do the elements a, b, c, d, h, v mean in a matrix like the ASFixedMatrix?

Estimated Reading Time: 2 Minutes

As in PostScript, in the Adobe PDF Library the matrix is the primary method used to control where PDF elements are placed on a page, and the size (scale) of those elements:

  1. a and b are the scale factors in X and Y positions of the movement in x
  2. c and d are scale factors in X and Y positions of the movement in y
  3. h and v are absolute displacement in X and Y distances

These values are expressed in the format [a b c d h v]. So the first four numbers of the matrix are scale factors, and have no units. The last two describe how the object twill be moved on the page. These two final values are in the units that were in effect prior to the transformation. That is, if you add scaling, so that the size of the element is doubled (a = 2), the units applying to values h and v will also double.

To scale an element evenly, use [Scale 0 0 Scale 0 0].

To move an element to a given point, use [1 0 0 1 Xpos Ypos].

The default unit is 1/72 of an inch, or one point. So [1 0 0 1 72 72] would move an object one inch (72 points) to the right (h, or horizontal) and one inch (72 points) up (v, or vertical).

Or, in another example, applying the matrix [2 0 0 1 -10 10] at a current position of [10,10] would take you to [10,20] in the transformed system:

Xnew = (a * Xold) + (c * Yold) + h and Ynew = (b * Xold) + (d * Yold) + v

where: a = 2; b = 0; c = 0; d = 1; h = -10; v = 10; Xold = 10; Yold = 10

thus:

10 = (2 * 10) + (0 * 10) + (-10) and 20 = (0 * 10) + (1 * 10) + 10

To rotate an image on the page a matrix, use the following algorithm as a guide:

  void PDFMatrixRotate(ASFixedMatrix *M, float Angle) 
    { 
    float  Ad = Angle; 
    double Sina, Cosa; 
    double Ma, Mb, Mc, Md;
        while (Ad < 0) 
            Ad += 360;
        while (Ad > 360.0) 
            Ad = Ad - 360.0;
        if (Ad < 0.0001) 
            return;
        Ad *= DEGREES_TO_RADIANS; 
        Ma = FixedToFloat (M->a); 
        Mb = FixedToFloat (M->b); 
        Mc = FixedToFloat (M->c); 
        Md = FixedToFloat (M->d);
        Sina = sin (Ad); 
        Cosa= cos (Ad);
        M->a = FloatToFixed ((Cosa * Ma) - (Sina * Mc)); 
        M->b = FloatToFixed ((Cosa * Mb) + (Sina * Ma)); 
        M->c = FloatToFixed ((Cosa * Mc) - (Sina * Md)); 
        M->d = FloatToFixed ((Cosa * Md) + (Sina * Mc));
        return; 
    }

 

For more information about matrices, see Section 8.3.3, “Common Transformations,” in the ISO 32000 Reference, page 117 and Section 8.3.4, “Transformation Matrices,” on page 119. 

What do the elements a, b, c, d, h, v mean in a matrix like the ASFixedMatrix?
  • COMMENT