Skip to Content

Can APDFL be used to simulate italic or bold if the system only has the regular typeface?

Estimated Reading Time: 2 Minutes

If you want to use a font that only offers a normal typeface—not bold, not italic—you can simulate bold by setting the same string several times at almost the same location, offset slightly. So the character would be printed twice in the same place on the page or screen. You can also set the their graphic state to both fill and stroke, instead of using only stroke, as you would with a normal font placement.

You can simulate italic by changing the angle via the matrix used in drawing the font. This will skew the matrix; the skew would include a tan statement to skew the x axis by angle a, and the y axis by angle b.

So you can skew both x and y, using a pair of tan statements. But the example below only skews x, because that’s all you need. So only a single tan statement appears. In this example we skew a 24 point text run by 15 degrees by changing the c value of the matrix.

memset(&textMatrix, 0, sizeof(textMatrix)); /* clear structure */

textMatrix.a = Int16ToFixed(24);  /* set font width and height */
textMatrix.d = Int16ToFixed(24);  /* to 24 point size */
textMatrix.h = Int16ToFixed(1*72);  /* x,y coordinate on page */
textMatrix.v = Int16ToFixed(2*72);  /* in this case, 1" x 2" */
 
memset(&skewMatrix, 0, sizeof(skewMatrix));  /* clear structure */
skewMatrix.a = Int16ToFixed(1);  /* */
skewMatrix.d = Int16ToFixed(1);  /* */
skewMatrix.c = Int16ToFixed(tan(15));  /* skew */
skewMatrix.h = Int16ToFixed(0);  /* */
skewMatrix.v = Int16ToFixed(0);  /* */

ASFixedMatrixConcat(&skewMatrix, &textMatrix, &skewMatrix);

After you set the skew, use your concatenated matrix for your text:

pdeText = PDETextCreate(); /* create new text run */

PDETextAdd(pdeText,   /* text container to add to */
  kPDETextRun, /* kPDETextRun, kPDETextChar */
  0, /* index */
  (Uns8 *)HelloWorldStr,   /* text to add */
  strlen(HelloWorldStr),   /* length of text */
  pdeFont,   /* font to apply to text */
  &gState, sizeof(gState),   /* graphic state to apply to text */
  NULL, 0,   /* text state and size of structure*/
  &skewMatrix,   /* transformation matrix for text */
  NULL);   /* stroke matrix */

For more information about skewing a matrix, see Section 8.3.3, “Common Transformations,” in the ISO 32000 Reference, page 117.

Note that most standard fonts offer normal, bold, and italic typefaces. You can use the process described here to set text as bold or italic for an obscure font. Maybe your employer created a custom font called “SeaStar,” for example, to use with the corporate logo and communications, and the SeaStar font does not offer bold or italic characters.

This process will work, but we don’t recommend it. Adobe PDF Library will not recognize the manual edits if it searches for fonts in a PDF document. If you use a custom font named SeaStar, and then manually make a set of characters boldface, the application will identify the embedded SeaStar font but it will not recognize SeaStar Bold characters.

Can APDFL be used to simulate italic or bold if the system only has the regular typeface?
  • COMMENT