Beispiel #1
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // g e n e r a t e F o n t                                            //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Generate PCLETTO font.                                             //
        //                                                                    //
        //--------------------------------------------------------------------//

        public Boolean generateFont(ref String pclFilename,
                                    Boolean symbolMapping,
                                    Boolean symSetUnbound,
                                    Boolean tabvmtxPresent,
                                    Boolean flagVMetrics,
                                    Byte [] fontName,
                                    Int32 sizeCharSet,
                                    UInt16 symSet,
                                    Byte [] conversionText)
        {
            Boolean flagOK = true;

            _baseHandler.initialise(_ttfHandler);

            _symbolMapping = symbolMapping;

            //----------------------------------------------------------------//
            //                                                                //
            // Open print file and stream.                                    //
            //                                                                //
            //----------------------------------------------------------------//

            try
            {
                flagOK = _baseHandler.streamOpen(ref pclFilename,
                                                 true,
                                                 ref _binWriter,
                                                 ref _opStream);
            }
            catch (Exception exc)
            {
                flagOK = false;

                MessageBox.Show(exc.ToString(),
                                "Failure to open output font file",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }

            if (flagOK)
            {
                //------------------------------------------------------------//
                //                                                            //
                // Generate font file contents.                               //
                //                                                            //
                //------------------------------------------------------------//

                Int32 len,
                      charClass;

                UInt16 numChars          = 0,
                       firstCode         = 0,
                       lastCode          = 0,
                       maxGlyphId        = 0,
                       maxComponentDepth = 0,
                       unitsPerEm        = 0;

                Boolean glyphZeroExists = false;

                Byte[] fontNameXL = new Byte[cSizeFontname];

                _ttfHandler.glyphReferencedUnmarkAll();

                _ttfHandler.getBasicMetrics(ref numChars,
                                            ref firstCode,
                                            ref lastCode,
                                            ref maxGlyphId,
                                            ref maxComponentDepth,
                                            ref unitsPerEm,
                                            ref glyphZeroExists);

                len = fontName.Length;

                if (len > cSizeFontname)
                {
                    len = cSizeFontname;
                }

                for (Int32 j = 0; j < len; j++)
                {
                    fontNameXL[j] = fontName[j];
                }

                for (Int32 j = len; j < cSizeFontname; j++)
                {
                    fontNameXL[j] = 0x20;
                }

                try
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Write font header.                                     //
                    //                                                        //
                    //--------------------------------------------------------//

                    writeHddr(glyphZeroExists,
                              symSetUnbound,
                              tabvmtxPresent,
                              flagVMetrics,
                              numChars,
                              symSet,
                              fontNameXL,
                              conversionText);

                    //--------------------------------------------------------//
                    //                                                        //
                    // Write BeginChar operator and associated Attribute List.//
                    //                                                        //
                    //--------------------------------------------------------//

                    PCLXLWriter.fontCharBegin(_binWriter,
                                              false,
                                              cSizeFontname,
                                              fontNameXL);

                    //--------------------------------------------------------//
                    //                                                        //
                    // Write Galley Character and font characters.            //
                    //                                                        //
                    //--------------------------------------------------------//

                    if (symSetUnbound)
                    {
                        charClass = 0;
                    }
                    else if ((tabvmtxPresent) && (flagVMetrics))
                    {
                        charClass = 2;
                    }
                    else
                    {
                        charClass = 1;
                    }

                    if (glyphZeroExists)
                    {
                        writeChar(charClass, 0xffff, 0, 0, 0, maxGlyphId);
                    }

                    writeCharSet(maxGlyphId, sizeCharSet, charClass,
                                 symSetUnbound);

                    //--------------------------------------------------------//
                    //                                                        //
                    // Write EndChar operator.                                //
                    //                                                        //
                    //--------------------------------------------------------//

                    PCLXLWriter.fontCharEnd(_binWriter, false);

                    //--------------------------------------------------------//
                    //                                                        //
                    // Close streams and files.                               //
                    //                                                        //
                    //--------------------------------------------------------//

                    _binWriter.Close();
                    _opStream.Close();

                    _ttfHandler.fontFileClose();
                }

                catch (Exception exc)
                {
                    flagOK = false;

                    MessageBox.Show(exc.ToString(),
                                    "Failure to write font file",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }

            return(flagOK);
        }