Beispiel #1
0
        public override byte[] GetData(ushort[] glyfIndexes)
        {
            MemoryStream stream = new MemoryStream();

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_version.X), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_version.Y), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ascent), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_descent), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_lineGap), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_advanceWidthMax), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_minLeftSideBearing), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_minRightSideBearing), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_xMaxExtent), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_caretSlopeRise), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_caretSlopeRun), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_caretOffset), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_reserved1), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_reserved2), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_reserved3), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_reserved4), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_metricDataFormat), 0, 2);

            ushort hMetricsCount = calculateNumOfLongHorMetrics(glyfIndexes);

            stream.Write(BinaryUtility.UInt16ToBytes(hMetricsCount), 0, 2);

            stream.Position = 0;
            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            return(data);
        }
Beispiel #2
0
        public override byte[] GetData(ushort[] glyfIndexes)
        {
            MemoryStream stream = new MemoryStream();

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_version.X), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_version.Y), 0, 2);

            ushort glyfsCount = (ushort)(glyfIndexes[glyfIndexes.Length - 1] + 1);

            stream.Write(BinaryUtility.UInt16ToBytes(glyfsCount), 0, 2);

            stream.Write(BinaryUtility.UInt16ToBytes(_maxPoints), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxContours), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxComponentPoints), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxComponentContours), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxZones), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxTwilightPoints), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxStorage), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxFunctionDefs), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxInstructionDefs), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxStackElements), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxSizeOfInstructions), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxComponentElements), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_maxComponentDepth), 0, 2);

            stream.Position = 0;
            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            return(data);
        }
Beispiel #3
0
        public override byte[] GetData(ushort[] glyfIndexes)
        {
            MemoryStream stream = new MemoryStream();

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_version.X), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_version.Y), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_fontRevision.X), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_fontRevision.Y), 0, 2);
            stream.Write(BinaryUtility.UInt32ToBytes(_checkSumAdjustment), 0, 4);
            stream.Write(BinaryUtility.UInt32ToBytes(_magicNumber), 0, 4);
            stream.Write(BinaryUtility.UInt16ToBytes(_flags), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_unitsPerEm), 0, 2);
            stream.Write(BinaryUtility.UInt64ToBytes((ulong)_created), 0, 8);
            stream.Write(BinaryUtility.UInt64ToBytes((ulong)_modified), 0, 8);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_xMin), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_yMin), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_xMax), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_yMax), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_macStyle), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_lowestRecPPEM), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_fontDirectionHint), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_indexToLocFormat), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_glyphDataFormat), 0, 2);

            stream.Position = 0;
            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            return(data);
        }
Beispiel #4
0
        public void Write(Stream stream)
        {
            byte[] bTag = System.Text.Encoding.ASCII.GetBytes(_tag);

            stream.Write(bTag, 0, bTag.Length);
            stream.Write(BinaryUtility.UInt32ToBytes((uint)_checksum), 0, 4);
            stream.Write(BinaryUtility.UInt32ToBytes((uint)_offset), 0, 4);
            stream.Write(BinaryUtility.UInt32ToBytes((uint)_length), 0, 4);
        }
Beispiel #5
0
 private void writeOffset(uint value, System.IO.MemoryStream stream)
 {
     if (_indexToLocFormat == 0)
     {
         stream.Write(BinaryUtility.UInt16ToBytes((ushort)(value / 2)), 0, 2);
     }
     else
     {
         stream.Write(BinaryUtility.UInt32ToBytes(value), 0, 4);
     }
 }
Beispiel #6
0
        public override byte[] GetData(ushort[] glyfIndexes)
        {
            MemoryStream stream = new MemoryStream();

            stream.Write(BinaryUtility.UInt16ToBytes(_version), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_xAvgCharWidth), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_usWeightClass), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_usWidthClass), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_fsType), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySubscriptXSize), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySubscriptYSize), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySubscriptXOffset), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySubscriptYOffset), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySuperscriptXSize), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySuperscriptYSize), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySuperscriptXOffset), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_ySuperscriptYOffset), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_yStrikeoutSize), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_yStrikeoutPosition), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)_sFamilyClass), 0, 2);

            stream.Write(_panose, 0, _panose.Length);
            for (int i = 0; i < _ulCharRange.Length; ++i)
            {
                stream.Write(BinaryUtility.UInt32ToBytes(_ulCharRange[i]), 0, 4);
            }
            stream.Write(_achVendID, 0, _achVendID.Length);

            stream.Write(BinaryUtility.UInt16ToBytes(_fsSelection), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_fsFirstCharIndex), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(_fsLastCharIndex), 0, 2);

            if (_version > 0)
            {
                stream.Write(BinaryUtility.UInt16ToBytes((ushort)_sTypoAscender), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes((ushort)_sTypoDescender), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes((ushort)_sTypoLineGap), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes(_usWinAscent), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes(_usWinDescent), 0, 2);
                stream.Write(BinaryUtility.UInt32ToBytes(_ulCodePageRange1), 0, 4);
                stream.Write(BinaryUtility.UInt32ToBytes(_ulCodePageRange2), 0, 4);
                stream.Write(BinaryUtility.UInt16ToBytes((ushort)_sxHeight), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes((ushort)_sCapHeight), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes(_usDefaultChar), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes(_usBreakChar), 0, 2);
                stream.Write(BinaryUtility.UInt16ToBytes(_usMaxContext), 0, 2);
            }

            stream.Position = 0;
            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            return(data);
        }
Beispiel #7
0
 private void initAIFF(Stream streamSound, PDFDictionaryStream streamOut)
 {
     byte[] word = new byte[4];
     streamOut.Dictionary.AddItem("E", new PDFName("Signed"));
     streamSound.Read(word, 0, word.Length);
     if (PDF.Encoding.GetString(word) == "COMM")
     {
         streamSound.Position += 4;
         byte[] buf = new byte[2];
         streamSound.Read(buf, 0, buf.Length);
         invert(buf);
         streamOut.Dictionary.AddItem("C", new PDFNumber(BitConverter.ToInt16(buf, 0)));
         streamSound.Position += 4;
         streamSound.Read(buf, 0, buf.Length);
         invert(buf);
         int bitPerDepth = BitConverter.ToInt16(buf, 0);
         streamOut.Dictionary.AddItem("B", new PDFNumber(bitPerDepth));
         buf = new byte[10];
         streamSound.Read(buf, 0, buf.Length);
         streamOut.Dictionary.AddItem("R", new PDFNumber((float)BinaryUtility.ConvertFromIeeeExtended(buf)));
         streamSound.Read(word, 0, word.Length);
         if (PDF.Encoding.GetString(word) == "SSND")
         {
             streamSound.Read(word, 0, word.Length);
             invert(word);
             int size = BitConverter.ToInt32(word, 0);
             streamSound.Read(word, 0, word.Length);
             invert(word);
             int offset = BitConverter.ToInt32(word, 0);
             streamSound.Read(word, 0, word.Length);
             invert(word);
             int blockSize = BitConverter.ToInt32(word, 0);
             streamSound.Position += offset;
             byte[] data = new byte[size];
             streamSound.Read(data, 0, data.Length);
             streamOut.GetStream().Write(data, 0, data.Length);
         }
         else
         {
             throw new PDFUnsupportedSoundFormatException();
         }
     }
     else
     {
         throw new PDFUnsupportedSoundFormatException();
     }
 }
Beispiel #8
0
        protected void writeHeader(Stream stream, uint tag)
        {
            stream.Write(BinaryUtility.UInt32ToBytes(tag), 0, 4);

            int numTables = _tables.Count;

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)numTables), 0, 2);

            uint maxPow      = maxPowerOf2(numTables);
            uint searchRange = maxPow * 16;

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)searchRange), 0, 2);

            int entrySelector = (int)Math.Log(maxPow, 2);

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)entrySelector), 0, 2);

            int rangeShift = (int)(numTables * 16 - searchRange);

            stream.Write(BinaryUtility.UInt16ToBytes((ushort)rangeShift), 0, 2);
        }
Beispiel #9
0
        public override byte[] GetData(ushort[] glyfIndexes)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            ms.Write(BinaryUtility.UInt16ToBytes((ushort)_format.X), 0, 2);
            ms.Write(BinaryUtility.UInt16ToBytes((ushort)_format.Y), 0, 2);
            ms.Write(BinaryUtility.UInt16ToBytes((ushort)_italicAngle.X), 0, 2);
            ms.Write(BinaryUtility.UInt16ToBytes((ushort)_italicAngle.Y), 0, 2);
            ms.Write(BinaryUtility.UInt16ToBytes((ushort)_underlinePosition), 0, 2);
            ms.Write(BinaryUtility.UInt16ToBytes((ushort)_underlineThickness), 0, 2);
            ms.Write(BinaryUtility.UInt32ToBytes((uint)_isFixedPitch), 0, 4);
            ms.Write(BinaryUtility.UInt32ToBytes((uint)_minMemType42), 0, 4);
            ms.Write(BinaryUtility.UInt32ToBytes((uint)_maxMemType42), 0, 4);
            ms.Write(BinaryUtility.UInt32ToBytes((uint)_minMemType1), 0, 4);
            ms.Write(BinaryUtility.UInt32ToBytes((uint)_maxMemType1), 0, 4);
            ms.Write(BinaryUtility.UInt32ToBytes((uint)_maxMemType1), 0, 4);
            ms.Write(BinaryUtility.UInt16ToBytes(0), 0, 2);

            byte[] tempFontData = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(tempFontData, 0, tempFontData.Length);
            return(tempFontData);
        }
Beispiel #10
0
        public override byte[] GetData(ushort[] glyfIndexes)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            int hMetricsCount = calculateNumOfLongHorMetrics(glyfIndexes);

            for (int i = 0; i < hMetricsCount; ++i)
            {
                if (i >= _hMetrics.Count)
                {
                    break;
                }

                LongHorMetric tmp = _hMetrics[i];
                ms.Write(BinaryUtility.UInt16ToBytes((ushort)tmp.AdvanceWidth), 0, 2);
                ms.Write(BinaryUtility.UInt16ToBytes((ushort)tmp.Lsb), 0, 2);
            }

            int glyfsCount           = glyfIndexes[glyfIndexes.Length - 1] + 1;
            int leftSideBearingCount = glyfsCount - hMetricsCount;

            if (leftSideBearingCount > 0 && _leftSideBearing.Count > 0)
            {
                int start = calculateStartLeftSideBearing(glyfIndexes);
                for (int i = 0; i < leftSideBearingCount; ++i)
                {
                    if (i >= _leftSideBearing.Count + start)
                    {
                        break;
                    }
                    ms.Write(BinaryUtility.UInt16ToBytes((ushort)_leftSideBearing[start + i]), 0, 2);
                }
            }

            byte[] tempFontData = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(tempFontData, 0, tempFontData.Length);
            return(tempFontData);
        }
Beispiel #11
0
        public byte[] GetData(FontMap map)
        {
            MemoryStream stream = new MemoryStream();

            byte[] cmapData = CMapMapFormat4.CreateData(map);

            stream.Write(BinaryUtility.UInt16ToBytes(0), 0, 2);                       //version
            stream.Write(BinaryUtility.UInt16ToBytes(1), 0, 2);                       //number subtables
            stream.Write(BinaryUtility.UInt16ToBytes(3), 0, 2);                       //platformID
            stream.Write(BinaryUtility.UInt16ToBytes(1), 0, 2);                       //platformSpecificID
            stream.Write(BinaryUtility.UInt32ToBytes(12), 0, 4);                      //offset
            stream.Write(BinaryUtility.UInt16ToBytes(4), 0, 2);                       //format
            stream.Write(BinaryUtility.UInt16ToBytes((ushort)cmapData.Length), 0, 2); //length
            stream.Write(BinaryUtility.UInt16ToBytes(0), 0, 2);                       //_language

            stream.Write(cmapData, 0, cmapData.Length);

            byte[] fontData = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(fontData, 0, fontData.Length);

            return(fontData);
        }
Beispiel #12
0
        public static byte[] CreateData(FontMap map)
        {
            MemoryStream stream     = new MemoryStream();
            List <char>  characters = map.Characters;

            characters.Sort();

            ushort firstCode = characters[0];

            stream.Write(BinaryUtility.UInt16ToBytes(firstCode), 0, 2);

            ushort count = (ushort)(characters[characters.Count - 1] - characters[0] + 1);

            stream.Write(BinaryUtility.UInt16ToBytes(count), 0, 2);

            ushort curIndex = 0;

            for (int i = 0; i < count; ++i)
            {
                if (i + firstCode == characters[curIndex])
                {
                    stream.Write(BinaryUtility.UInt16ToBytes(map.GetGlyfIndex(characters[curIndex])), 0, 2);
                    ++curIndex;
                }
                else
                {
                    stream.Write(BinaryUtility.UInt16ToBytes(0), 0, 2);
                }
            }

            byte[] data = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(data, 0, data.Length);

            return(data);
        }
Beispiel #13
0
        public static byte[] CreateData(FontMap map)
        {
            List <char> characters = map.Characters;

            characters.Sort();

            List <UInt16> endCode       = new List <ushort>();
            List <UInt16> startCode     = new List <ushort>();
            List <UInt16> idDelta       = new List <ushort>();
            List <UInt16> idRangeOffset = new List <ushort>();

            ushort delta = 0;

            for (int i = 0; i < characters.Count; ++i)
            {
                delta = (ushort)(map.GetGlyfIndex(characters[i]) - characters[i] + 65536);

                startCode.Add(characters[i]);
                idDelta.Add(delta);
                idRangeOffset.Add(0);

                int j;
                for (j = i; j < characters.Count; ++j)
                {
                    if (j == characters.Count - 1 || characters[j] + 1 != characters[j + 1] ||
                        delta != map.GetGlyfIndex(characters[j]) - characters[j] + 65536)
                    {
                        break;
                    }
                }

                i = j;
                endCode.Add(characters[i]);
            }

            endCode.Add(65535);
            startCode.Add(65535);
            idDelta.Add(1);
            idRangeOffset.Add(0);

            ushort segCountX2    = (ushort)(endCode.Count * 2);
            ushort power         = 0;
            ushort maxPowOf2     = getMaxPowerOf2((ushort)(segCountX2 / 2), ref power);
            ushort searchRange   = (ushort)(2 * maxPowOf2);
            ushort entrySelector = power;
            ushort rangeShift    = (ushort)(segCountX2 - searchRange);

            MemoryStream stream = new MemoryStream();

            stream.Write(BinaryUtility.UInt16ToBytes(segCountX2), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(searchRange), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(entrySelector), 0, 2);
            stream.Write(BinaryUtility.UInt16ToBytes(rangeShift), 0, 2);

            for (int i = 0; i < endCode.Count; ++i)
            {
                stream.Write(BinaryUtility.UInt16ToBytes(endCode[i]), 0, 2);
            }

            stream.Write(BinaryUtility.UInt16ToBytes(0), 0, 2);

            for (int i = 0; i < startCode.Count; ++i)
            {
                stream.Write(BinaryUtility.UInt16ToBytes(startCode[i]), 0, 2);
            }

            for (int i = 0; i < idDelta.Count; ++i)
            {
                stream.Write(BinaryUtility.UInt16ToBytes(idDelta[i]), 0, 2);
            }

            for (int i = 0; i < idRangeOffset.Count; ++i)
            {
                stream.Write(BinaryUtility.UInt16ToBytes(idRangeOffset[i]), 0, 2);
            }

            byte[] buf = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buf, 0, buf.Length);

            return(buf);
        }