/* * vAddHdrFtr - add a header or footer */ static void vAddHdrFtr(diagram_type *pDiag, const hdrftr_block_type *pHdrFtrInfo) { output_type *pStart, *pPrev, *pNext; fail(pDiag == NULL); fail(pHdrFtrInfo == NULL); vStartOfParagraphPDF(pDiag, 0); pStart = pHdrFtrInfo->pText; while (pStart != NULL) { pNext = pStart; while (pNext != NULL && (pNext->tNextFree != 1 || (pNext->szStorage[0] != PAR_END && pNext->szStorage[0] != HARD_RETURN))) { pNext = pNext->pNext; } if (pNext == NULL) { if (bOutputContainsText(pStart)) { vAlign2Window(pDiag, pStart, lChar2MilliPoints(DEFAULT_SCREEN_WIDTH), ALIGNMENT_LEFT); } else { vMove2NextLinePDF(pDiag, pStart->usFontSize); } break; } fail(pNext->tNextFree != 1); fail(pNext->szStorage[0] != PAR_END && pNext->szStorage[0] != HARD_RETURN); if (pStart != pNext) { /* There is something to print */ pPrev = pNext->pPrev; fail(pPrev->pNext != pNext); /* Cut the chain */ pPrev->pNext = NULL; if (bOutputContainsText(pStart)) { /* Print it */ vAlign2Window(pDiag, pStart, lChar2MilliPoints(DEFAULT_SCREEN_WIDTH), ALIGNMENT_LEFT); } else { /* Just an empty line */ vMove2NextLinePDF(pDiag, pStart->usFontSize); } /* Repair the chain */ pPrev->pNext = pNext; } if (pNext->szStorage[0] == PAR_END) { vEndOfParagraphPDF(pDiag, pNext->usFontSize, (long)pNext->usFontSize * 200); } pStart = pNext->pNext; } } /* end of vAddHdrFtr */
/* * lComputeStringWidth - compute the string width * * Note: the fontsize is specified in half-points! * the stringlength is specified in bytes, not characters! * * Returns the string width in millipoints */ long lComputeStringWidth(const char *szString, size_t tStringLength, drawfile_fontref tFontRef, USHORT usFontSize) { USHORT *ausCharWidths; UCHAR *pucChar; long lRelWidth; size_t tIndex; int iFontRef; fail(szString == NULL); fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE); if (szString[0] == '\0' || tStringLength == 0) { /* Empty string */ return 0; } if (eEncoding == encoding_utf_8) { fail(!bUsePlainText); return lChar2MilliPoints( utf8_strwidth(szString, tStringLength)); } if (bUsePlainText) { /* No current font, use "systemfont" */ return lChar2MilliPoints(tStringLength); } if (eEncoding == encoding_cyrillic) { /* FIXME: until the character tables are available */ return (long)((tStringLength * 600L * (long)usFontSize + 1) / 2); } DBG_DEC_C(eEncoding != encoding_latin_1 && eEncoding != encoding_latin_2, eEncoding); fail(eEncoding != encoding_latin_1 && eEncoding != encoding_latin_2); /* Compute the relative string width */ iFontRef = (int)(UCHAR)tFontRef; if (eEncoding == encoding_latin_2) { ausCharWidths = ausCharacterWidths2[iFontRef]; } else { ausCharWidths = ausCharacterWidths1[iFontRef]; } lRelWidth = 0; for (tIndex = 0, pucChar = (UCHAR *)szString; tIndex < tStringLength; tIndex++, pucChar++) { lRelWidth += (long)ausCharWidths[(int)*pucChar]; } /* Compute the absolute string width */ return (lRelWidth * (long)usFontSize + 1) / 2; } /* end of lComputeStringWidth */
/* * lComputeStringWidth - compute the string width * * Returns the string width in millipoints */ long lComputeStringWidth(const char *szString, size_t tStringLength, drawfile_fontref tFontRef, USHORT usFontSize) { font_string tStr; os_error *e; fail(szString == NULL); fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE); if (szString[0] == '\0' || tStringLength == 0) { /* Empty string */ return 0; } if (tStringLength == 1 && szString[0] == TABLE_SEPARATOR) { /* Font_strwidth doesn't like control characters */ return 0; } if (tFontCurr == (font_handle)-1) { /* No current font, use systemfont */ return lChar2MilliPoints(tStringLength); } tStr.s = (char *)szString; tStr.x = INT_MAX; tStr.y = INT_MAX; tStr.split = -1; tStr.term = tStringLength; e = Font_StringWidth(&tStr); if (e == NULL) { return (long)tStr.x; } DBG_DEC(e->errnum); DBG_MSG(e->errmess); DBG_DEC(tStringLength); DBG_MSG(szString); werr(0, "String width error %d: %s", e->errnum, e->errmess); return lChar2MilliPoints(tStringLength); } /* end of lComputeStringWidth */