Example #1
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // c h e c k S y m S e t F i l e                                      //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Check symbol set file to see if it starts with a 'symbol set       //
        // identifier' sequence; if so, return the identifier and first and   //
        // last code-point values.                                            //
        // The symbol set map id stored in the special 'user-defined' symbol  //
        // set instance.                                                      //
        //                                                                    //
        // TODO perhaps we ought to check that symbol set control (make       //
        // permanent) is also present?                                        //
        //                                                                    //
        //--------------------------------------------------------------------//

        public static Boolean checkSymSetFile(
            String filename,
            ref UInt16 symSetNo,
            ref UInt16 firstCode,
            ref UInt16 lastCode,
            ref PCLSymSetTypes.eIndex symSetType)
        {
            Boolean flagOK = true;

            Boolean fileOpen = false;

            Int64 fileSize = 0,
                  offset   = 0;

            //----------------------------------------------------------------//
            //                                                                //
            // Read file to obtain characteristics.                           //
            //                                                                //
            //----------------------------------------------------------------//

            fileOpen = symSetFileOpen(filename, ref fileSize);

            if (!fileOpen)
            {
                flagOK = false;

                MessageBox.Show("Unable to open symbol set definition" +
                                " file '" + filename + "'",
                                "Symbol Set file invalid",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
            else
            {
                firstCode = 0;
                lastCode  = 0;

                flagOK = readSymSetId(fileSize,
                                      ref offset,
                                      ref symSetNo);
                if (!flagOK)
                {
                    MessageBox.Show("Symbol set definition" +
                                    " file '" + filename + "':\r\n\r\n" +
                                    "File does not start with" +
                                    " 'symbol set Id' escape sequence",
                                    "Symbol Set file invalid",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                else
                {
                    Byte symSetFormat = 0;
                    Byte symSetTypeId = 0;

                    flagOK = readSymSetHddr(filename,
                                            fileSize,
                                            symSetNo,
                                            ref symSetFormat,
                                            ref symSetTypeId,
                                            ref offset,
                                            ref firstCode,
                                            ref lastCode);

                    if (!flagOK)
                    {
                        MessageBox.Show("Symbol set definition" +
                                        " file '" + filename + "':\r\n\r\n" +
                                        "Header is invalid",
                                        "Symbol Set file invalid",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                    else
                    {
                        flagOK = readAndStoreSymSetMap(offset,
                                                       symSetNo,
                                                       firstCode,
                                                       lastCode);

                        if (!flagOK)
                        {
                            MessageBox.Show("Symbol set definition" +
                                            " file '" + filename + "':\r\n\r\n" +
                                            "Mapping data is invalid",
                                            "Symbol Set file invalid",
                                            MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                        else
                        {
                            symSetType = PCLSymSetTypes.getIndexForIdPCL(symSetTypeId);
                        }
                    }
                }

                symSetFileClose();
            }

            return(flagOK);
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // g e t F o n t S e l e c t i o n D a t a                            //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Read font selection characteristics from PCL soft font descriptor. //
        //                                                                    //
        //--------------------------------------------------------------------//

        private static Boolean getFontSelectionData(
            Int32 hddrOffset,
            Int32 hddrLen,
            ref Boolean proportional,
            ref Boolean scalable,
            ref Boolean bound,
            ref Double pitch,
            ref Double height,
            ref UInt16 style,
            ref Int16 weight,
            ref UInt16 typeface,
            ref UInt16 symSetNo,
            ref PCLSymSetTypes.eIndex symSetType)
        {
            Boolean OK = true;

            UInt16 hddrDescLen;

            Byte[] hddr;

            Boolean bitmapFont = false;

            UInt16 dotResX,
                   dotResY;

            Byte[] buf = new Byte[2];

            _ipStream.Seek(hddrOffset, SeekOrigin.Begin);

            _binReader.Read(buf, 0, 2);

            hddrDescLen = (UInt16)((buf[0] << 8) + buf[1]);

            hddr = new Byte[hddrDescLen];       // if universal bitmap, want whole header read, inclduing segments

            _ipStream.Seek(hddrOffset, SeekOrigin.Begin);

            _binReader.Read(hddr, 0, hddrDescLen);

            //----------------------------------------------------------------//

            ePCLFontFormat hddrFormat;

            hddrFormat = (ePCLFontFormat)hddr[2];

            switch (hddrFormat)
            {
            case ePCLFontFormat.Bitmap:
                bitmapFont = true;
                break;

            case ePCLFontFormat.BitmapResSpec:
                bitmapFont = true;
                break;

            case ePCLFontFormat.IntellifontBound:
                //  intelliFont = true;
                break;

            case ePCLFontFormat.IntellifontUnbound:
                //  intelliFont = true;
                break;

            case ePCLFontFormat.TrueType:
                //  truetypeFont = true;
                break;

            case ePCLFontFormat.Universal:
                //  universalFont = true;
                if (hddr[70] == 254)        // scaling technology
                {
                    bitmapFont = true;
                }
                break;
            }

            //----------------------------------------------------------------//

            if (bitmapFont)
            {
                scalable = false;
            }
            else
            {
                scalable = true;
            }

            //----------------------------------------------------------------//

            dotResX = _defaultPCLDotRes;
            dotResY = _defaultPCLDotRes;

            if (hddrFormat == ePCLFontFormat.Universal)
            {
                if (bitmapFont)     // scaling technology = 254
                {
                    // need to read BR segment to get resolutions

                    Boolean endSegs = false;


                    Byte[] segData;

                    Int32 segDataLen;
                    Int32 segSize;
                    Int32 segType;
                    Int32 offset;

                    segDataLen = hddrLen - hddrDescLen;

                    segData = new Byte[segDataLen];

                    //      _ipStream.Seek (hddrOffset, SeekOrigin.Begin); // already at correct position ?

                    _binReader.Read(segData, 0, segDataLen);

                    offset = 0;

                    while (!endSegs)
                    {
                        //----------------------------------------------------//
                        //                                                    //
                        // Segment Type and Length data is in buffer.         //
                        //                                                    //
                        //----------------------------------------------------//

                        segType = (segData[offset] << 8) +
                                  segData[offset + 1];

                        segSize = (segData[offset + 2] << 24) +
                                  (segData[offset + 3] << 16) +
                                  (segData[offset + 4] << 8) +
                                  segData[offset + 5];

                        if ((segType == 0x4252) &&
                            ((offset + 6 + segSize) < hddrLen))
                        {
                            // BR
                            dotResX = (UInt16)((segData[offset + 6] << 8) +
                                               segData[offset + 7]);
                            dotResY = (UInt16)((segData[offset + 8] << 8) +
                                               segData[offset + 9]);
                        }
                        else if (segType == 0xffff)
                        {
                            // null

                            endSegs = true;
                        }

                        offset += (6 + segSize);

                        if ((offset + 6) > hddrLen)
                        {
                            endSegs = true;
                        }
                    }
                }
            }
            else if (hddrFormat == ePCLFontFormat.BitmapResSpec)
            {
                dotResX = (UInt16)((hddr[64] << 8) + hddr[65]);
                dotResY = (UInt16)((hddr[66] << 8) + hddr[67]);
            }
            else //if (hddrFormat == PCLSoftFonts.eIdHddrFormat.BitmapResSpec)
            {
                dotResX = _defaultPCLDotRes;
                dotResY = _defaultPCLDotRes;
            }

            //----------------------------------------------------------------//

            symSetType = PCLSymSetTypes.getIndexForIdPCL(hddr[3]);

            bound = PCLSymSetTypes.isBound((Int32)symSetType);

            //----------------------------------------------------------------//

            if (hddr[13] == 0)
            {
                proportional = false;
            }
            else
            {
                proportional = true;
            }

            //----------------------------------------------------------------//

            symSetNo = (UInt16)((hddr[14] << 8) + hddr[15]);

            //----------------------------------------------------------------//

            if (bitmapFont)
            {
                UInt16 dotsQtr = 0;
                UInt16 dotsExt = 0;
                Double dotsK   = 0.0;

                dotsQtr = (UInt16)((hddr[16] << 8) + hddr[17]);
                dotsExt = (UInt16)(hddr[40]);
                dotsK   = (dotsQtr << 8) + dotsExt;

                if ((dotsQtr == 0) && (dotsExt == 0))
                {
                    pitch = 0.0;
                }
                else
                {
                    dotsK = (dotsQtr << 8) + dotsExt;
                    pitch = (dotResX << 10) / dotsK;
                }

                dotsQtr = (UInt16)((hddr[18] << 8) + hddr[19]);
                dotsExt = (UInt16)(hddr[41]);

                if ((dotsQtr == 0) && (dotsExt == 0))
                {
                    height = 0.0;
                }
                else
                {
                    dotsK  = (dotsQtr << 8) + dotsExt;
                    height = (dotsK * 72) / (dotResY << 10);
                }
            }
            else
            {
                pitch  = 0.0;
                height = 0.0;
            }

            //----------------------------------------------------------------//

            style    = (UInt16)((hddr[4] << 8) + hddr[23]);
            weight   = (Int16)hddr[24];
            typeface = (UInt16)((hddr[26] << 8) + hddr[25]);

            //----------------------------------------------------------------//

            return(OK);
        }