//--------------------------------------------------------------------// // M e t h o d // // w r i t e H d d r // //--------------------------------------------------------------------// // // // Generate font header descriptor, segmented data and checksum byte. // // // //--------------------------------------------------------------------// private Boolean writeHddr(ref Boolean monoSpaced, Boolean fmt16, Boolean segGTLast, Boolean usePCLT, Boolean glyphZeroExists, Boolean symSetUnbound, Boolean tabvmtxPresent, Boolean flagVMetrics, Byte symSetType, UInt16 firstCode, UInt16 lastCode, UInt16 numChars, UInt16 unitsPerEm, UInt16 symSet, UInt16 style, SByte strokeWeight, UInt16 typeface, UInt64 charCollComp, Byte [] conversionText) { Boolean flagOK = true; UInt16 cellWidth = 0, cellHeight = 0, textWidth = 0, textHeight = 0, pitch = 0, xHeight = 0, capHeight = 0, mUlinePosU = 0, mUlineDep = 0; Int16 mUlinePos = 0; UInt32 fontNo = 0; Int32 sum; Int32 convTextLen; Int32 hddrLen; Byte mod256; Byte serifStyle = 0; Byte fontFormat; Byte fontType; Byte fontSpacing; SByte widthType = 0; Byte [] fontNamePCLT = new Byte [ToolSoftFontGenTTF.cSizeFontname]; Byte [] panoseData = new Byte [ToolSoftFontGenTTF.cSizePanose]; Byte [] hddrDesc = new Byte [cSizeHddrDesc]; //----------------------------------------------------------------// // // // Get relevant PCL data from TrueType font. // // // //----------------------------------------------------------------// monoSpaced = false; _ttfHandler.getPCLFontHeaderData(usePCLT, ref monoSpaced, ref cellWidth, ref cellHeight, ref textWidth, ref textHeight, ref pitch, ref xHeight, ref capHeight, ref mUlinePos, ref mUlineDep, ref fontNo, ref serifStyle, ref widthType, ref fontNamePCLT, ref panoseData); mUlinePosU = (UInt16)mUlinePos; //----------------------------------------------------------------// if (fmt16) { fontFormat = 16; // Format = Universal } else { fontFormat = 15; // Format = TrueType scalable } if (monoSpaced) { fontSpacing = 0; // Spacing = Fixed-pitch } else { fontSpacing = 1; // Spacing = Proportional } if (symSetUnbound) { fontType = 11; // Type = unbound Unicode-indexed firstCode = 0; lastCode = numChars; } else { fontType = symSetType; // Type = as per target symbol set } //----------------------------------------------------------------// // // // Calculate total size of header. // // Write PCL 'download header' escape sequence. // // // //----------------------------------------------------------------// convTextLen = conversionText.Length; hddrLen = cSizeHddrDesc + _baseHandler.getHddrSegmentsLen( false, fmt16, glyphZeroExists, symSetUnbound, tabvmtxPresent, flagVMetrics, convTextLen) + cSizeHddrTrail; if ((hddrLen > cSizeHddrFmt15Max) && (!fmt16)) { flagOK = false; MessageBox.Show("Header length of '" + hddrLen + "' is incompatible with 'format 15'" + " font.", "Soft font header invalid", MessageBoxButton.OK, MessageBoxImage.Error); } else { PCLWriter.fontDownloadHddr(_binWriter, (UInt32)hddrLen); //------------------------------------------------------------// // // // Write font header descriptor. // // // //------------------------------------------------------------// hddrDesc [0] = msByte(cSizeHddrDesc); hddrDesc [1] = lsByte(cSizeHddrDesc); hddrDesc [2] = fontFormat; // Font Format hddrDesc [3] = fontType; // Font Type hddrDesc [4] = msByte(style); // Style MSB hddrDesc [5] = 0; // Reserved hddrDesc [6] = 0; // Baseline Position MSB hddrDesc [7] = 0; // Baseline Position LSB hddrDesc [8] = msByte(cellWidth); // Cell width MSB hddrDesc [9] = lsByte(cellWidth); // Cell Width LSB hddrDesc [10] = msByte(cellHeight); // Cell Height MSB hddrDesc [11] = lsByte(cellHeight); // Cell Height LSB hddrDesc [12] = 0; // Orientation hddrDesc [13] = fontSpacing; // Spacing hddrDesc [14] = msByte(symSet); // Symbol Set MSB hddrDesc [15] = lsByte(symSet); // Symbol Set LSB hddrDesc [16] = msByte(pitch); // Pitch MSB hddrDesc [17] = lsByte(pitch); // Pitch LSB hddrDesc [18] = 0; // Height MSB hddrDesc [19] = 0; // Height LSB hddrDesc [20] = msByte(xHeight); // xHeight MSB hddrDesc [21] = msByte(xHeight); // xHeight LSB hddrDesc [22] = (Byte)widthType; // Width Type hddrDesc [23] = lsByte(style); // Style LSB hddrDesc [24] = (Byte)strokeWeight; // Stroke Weight hddrDesc [25] = lsByte(typeface); // Typeface LSB hddrDesc [26] = msByte(typeface); // Typeface MSB hddrDesc [27] = serifStyle; // Serif Style hddrDesc [28] = 2; // Quality = Letter hddrDesc [29] = 0; // Placement hddrDesc [30] = 0; // Underline Position hddrDesc [31] = 0; // Underline Thickness hddrDesc [32] = msByte(textHeight); // Text Height MSB hddrDesc [33] = lsByte(textHeight); // Text Height LSB hddrDesc [34] = msByte(textWidth); // Text Width MSB hddrDesc [35] = lsByte(textWidth); // Text Width LSB hddrDesc [36] = msByte(firstCode); // First Code MSB hddrDesc [37] = lsByte(firstCode); // First Code LSB hddrDesc [38] = msByte(lastCode); // Last Code MSB hddrDesc [39] = lsByte(lastCode); // Last Code LSB hddrDesc [40] = 0; // Pitch Extended hddrDesc [41] = 0; // Height Extended hddrDesc [42] = msByte(capHeight); // Cap Height MSB hddrDesc [43] = lsByte(capHeight); // Cap Height LSB hddrDesc [44] = msByte(msUInt16(fontNo)); // Font No. byte 0 hddrDesc [45] = lsByte(msUInt16(fontNo)); // Font No. byte 1 hddrDesc [46] = msByte(lsUInt16(fontNo)); // Font No. byte 2 hddrDesc [47] = lsByte(lsUInt16(fontNo)); // Font No. byte 3 hddrDesc [48] = fontNamePCLT [0]; // Font Name byte 0 hddrDesc [49] = fontNamePCLT [1]; // Font Name byte 1 hddrDesc [50] = fontNamePCLT [2]; // Font Name byte 2 hddrDesc [51] = fontNamePCLT [3]; // Font Name byte 3 hddrDesc [52] = fontNamePCLT [4]; // Font Name byte 4 hddrDesc [53] = fontNamePCLT [5]; // Font Name byte 5 hddrDesc [54] = fontNamePCLT [6]; // Font Name byte 6 hddrDesc [55] = fontNamePCLT [7]; // Font Name byte 7 hddrDesc [56] = fontNamePCLT [8]; // Font Name byte 8 hddrDesc [57] = fontNamePCLT [9]; // Font Name byte 9 hddrDesc [58] = fontNamePCLT [10]; // Font Name byte 10 hddrDesc [59] = fontNamePCLT [11]; // Font Name byte 11 hddrDesc [60] = fontNamePCLT [12]; // Font Name byte 12 hddrDesc [61] = fontNamePCLT [13]; // Font Name byte 13 hddrDesc [62] = fontNamePCLT [14]; // Font Name byte 14 hddrDesc [63] = fontNamePCLT [15]; // Font Name byte 15 hddrDesc [64] = msByte(unitsPerEm); // Scale Factor MSB hddrDesc [65] = lsByte(unitsPerEm); // Scale Factor LSB hddrDesc [66] = msByte(mUlinePosU); // Master U-line Pos. MSB hddrDesc [67] = lsByte(mUlinePosU); // Master U-line Pos. LSB hddrDesc [68] = msByte(mUlineDep); // Master U-line Dep. MSB hddrDesc [69] = lsByte(mUlineDep); // Master U-line Dep. LSB hddrDesc [70] = 1; // Scaling Tech. = TrueType hddrDesc [71] = 0; // Variety _baseHandler.writeBuffer(cSizeHddrDesc, hddrDesc); //------------------------------------------------------------// // // // Start calculating checksum byte from byte 64 onwards of // // header. // // // //------------------------------------------------------------// sum = 0; for (Int32 i = 64; i < cSizeHddrDesc; i++) { sum += hddrDesc [i]; } mod256 = (Byte)(sum % 256); //------------------------------------------------------------// // // // Write header segmented data. // // // //------------------------------------------------------------// flagOK = _baseHandler.writeHddrSegments(false, fmt16, segGTLast, glyphZeroExists, symSetUnbound, tabvmtxPresent, flagVMetrics, charCollComp, conversionText, panoseData, ref mod256); if (flagOK) { //--------------------------------------------------------// // // // Write 'reserved byte' and (calculated) checksum byte. // // // //--------------------------------------------------------// mod256 = (Byte)((256 - mod256) % 256); Byte [] trailer = new Byte [cSizeHddrTrail]; trailer [0] = 0; trailer [1] = mod256; _baseHandler.writeBuffer(cSizeHddrTrail, trailer); } } return(flagOK); }
//--------------------------------------------------------------------// // M e t h o d // // w r i t e H d d r // //--------------------------------------------------------------------// // // // Generate font header descriptor, segmented data and checksum byte. // // // //--------------------------------------------------------------------// private void writeHddr(Boolean glyphZeroExists, Boolean symSetUnbound, Boolean tabvmtxPresent, Boolean flagVMetrics, UInt16 numChars, UInt16 symSet, Byte[] fontNameXL, Byte[] conversionText) { Byte mod256 = 0; Byte[] hddrDesc = new Byte[cSizeHddrDesc]; Byte[] panoseData = new Byte[ToolSoftFontGenTTF.cSizePanose]; //----------------------------------------------------------------// // // // Write BeginFontHeader Operator and associated Attribute List. // // // //----------------------------------------------------------------// PCLXLWriter.fontHddrBegin(_binWriter, false, cSizeFontname, fontNameXL, 0); //----------------------------------------------------------------// // // // Write Format 0 font header. // // // //----------------------------------------------------------------// hddrDesc[0] = 0; // Format hddrDesc[1] = (Byte)PCLXLAttrEnums.eVal.ePortraitOrientation; hddrDesc[2] = msByte(symSet); // Symbol set MSB hddrDesc[3] = lsByte(symSet); // Symbol Set LSB hddrDesc[4] = 1; // Scaling = TrueType hddrDesc[5] = 0; // Variety hddrDesc[6] = msByte(numChars); // NumChars MSB hddrDesc[7] = lsByte(numChars); // NumChars LSB _baseHandler.writeHddrFragment(true, cSizeHddrDesc, hddrDesc, ref mod256); //----------------------------------------------------------------// // // // Write segmented data. // // // //----------------------------------------------------------------// mod256 = 0; // not actually required for PCL XL panoseData = _ttfHandler.PanoseData; _baseHandler.writeHddrSegments(true, true, false, glyphZeroExists, symSetUnbound, tabvmtxPresent, flagVMetrics, 0, // not used for PCL XL // conversionText, panoseData, ref mod256); //----------------------------------------------------------------// // // // Write BeginFontHeader Operator and associated Attribute List. // // // //----------------------------------------------------------------// PCLXLWriter.fontHddrEnd(_binWriter, false); }