コード例 #1
0
ファイル: LayerTextType.cs プロジェクト: lwx1010/2D_XProject
        public LayerTextType(PsdBinaryReader reader)
        {
            version   = reader.ReadUInt16();           // 1 = Photoshop 5.0
            transform = new Matrix2D(reader);

            //Font info:
            // fontVersion
            reader.ReadUInt16();             // 6 = Photoshop 5.0
            ushort faceCount = reader.ReadUInt16();

            fontInfos = new List <FontInfo>();
            for (int i = 0; i < faceCount; i++)
            {
                fontInfos.Add(new FontInfo(reader));
            }

            //TODO: make classes of styles as well...
            ushort styleCount = reader.ReadUInt16();

            for (int i = 0; i < styleCount; i++)
            {
                // mark
                reader.ReadUInt16();
                // faceMark
                reader.ReadUInt16();
                // size
                reader.ReadUInt32();
                // tracking
                reader.ReadUInt32();
                // kerning
                reader.ReadUInt32();
                // leading
                reader.ReadUInt32();
                // baseShift
                reader.ReadUInt32();

                // autoKern
                reader.ReadByte();

                if (version <= 5)
                {
                    // extra
                    reader.ReadByte();
                }

                // rotate
                reader.ReadByte();
            }

            //Text information
            // type
            reader.ReadUInt16();
            // scalingFactor
            reader.ReadUInt32();
            // characterCount
            reader.ReadUInt32();
            // horizontalPlacement
            reader.ReadUInt32();
            // verticalPlacement
            reader.ReadUInt32();
            // selectStart
            reader.ReadUInt32();
            // selectEnd
            reader.ReadUInt32();

            ushort lineCount = reader.ReadUInt16();

            for (int i = 0; i < lineCount; i++)
            {
                // characterCountLine
                reader.ReadUInt32();
                // orientation
                reader.ReadUInt16();
                // alignment
                reader.ReadUInt16();
                // doubleByteChar
                reader.ReadUInt16();
                // style
                reader.ReadUInt16();
            }

            // colorSpace
            reader.ReadUInt16();
            for (int i = 0; i < 4; i++)
            {
                reader.ReadUInt16();                 //Color compensation
            }
            // antiAlias
            reader.ReadByte();
        }
コード例 #2
0
        public LayerText(PsdBinaryReader psdReader, int dataLength)
        {
            Data = psdReader.ReadBytes((int)dataLength);
            var reader = new PsdBinaryReader(new System.IO.MemoryStream(Data), psdReader);

            // PhotoShop version
            reader.ReadUInt16();

            Transform = new Matrix2D(reader);

            // TextVersion
            reader.ReadUInt16(); //2 bytes, =50. For Photoshop 6.0.

            // DescriptorVersion
            reader.ReadUInt32();                           //4 bytes,=16. For Photoshop 6.0.

            TxtDescriptor = DynVal.ReadDescriptor(reader); //Text descriptor

            // WarpVersion
            reader.ReadUInt16(); //2 bytes, =1. For Photoshop 6.0.

            engineData       = (Dictionary <string, object>)TxtDescriptor.Children.Find(c => c.Name == "EngineData").Value;
            StylesheetReader = new TdTaStylesheetReader(engineData);

            Dictionary <string, object> d = StylesheetReader.GetStylesheetDataFromLongestRun();

            Text     = StylesheetReader.Text;
            FontName = TdTaParser.getString(StylesheetReader.getFontSet()[(int)TdTaParser.query(d, "Font")], "Name$");
            FontSize = (double)TdTaParser.query(d, "FontSize");

            try
            {
                FauxBold = TdTaParser.getBool(d, "FauxBold");
            }
            catch (KeyNotFoundException)
            {
                FauxBold = false;
            }

            try
            {
                FauxItalic = TdTaParser.getBool(d, "FauxItalic");
            }
            catch (KeyNotFoundException)
            {
                FauxItalic = false;
            }

            try
            {
                Underline = TdTaParser.getBool(d, "Underline");
            }
            catch (KeyNotFoundException)
            {
                Underline = false;
            }

            FillColor = TdTaParser.getColor(d, "FillColor");

            try
            {
                OutlineWidth = (double)TdTaParser.query(d, "OutlineWidth");
            }
            catch (KeyNotFoundException)
            {
                OutlineWidth = 0f;
            }

            try
            {
                StrokeColor = TdTaParser.getColor(d, "StrokeColor");
            }
            catch (KeyNotFoundException)
            {
                StrokeColor = 0;
            }
        }
コード例 #3
0
        public LayerText(PsdBinaryReader psdReader, int dataLength)
        {
            Data = psdReader.ReadBytes((int)dataLength);
            var reader = new PsdBinaryReader(new System.IO.MemoryStream(Data), psdReader);

            // PhotoShop version
            reader.ReadUInt16();

            Transform = new Matrix2D(reader);

            // TextVersion
            reader.ReadUInt16(); //2 bytes, =50. For Photoshop 6.0.

            // DescriptorVersion
            reader.ReadUInt32();                           //4 bytes,=16. For Photoshop 6.0.

            TxtDescriptor = DynVal.ReadDescriptor(reader); //Text descriptor

            // WarpVersion
            ushort wrapVersion = reader.ReadUInt16(); //2 bytes, =1. For Photoshop 6.0.

            // DescriptorVersion
            uint wrapDescriptorVersion = reader.ReadUInt32();

            DynVal warpDescriptor = DynVal.ReadDescriptor(reader);

            //            double left = reader.ReadDouble();
            //            double top = reader.ReadDouble();
            //            double right = reader.ReadDouble();
            //            double bottom = reader.ReadDouble();

            byte[] datas = reader.ReadBytes(32);

            engineData       = (Dictionary <string, object>)TxtDescriptor.Children.Find(c => c.Name == "EngineData").Value;
            StylesheetReader = new TdTaStylesheetReader(engineData);

            Dictionary <string, object> d = StylesheetReader.GetStylesheetDataFromLongestRun();

            Text     = StylesheetReader.Text;
            FontName = TdTaParser.getString(StylesheetReader.getFontSet()[(int)TdTaParser.query(d, "Font")], "Name$");
            FontSize = (double)TdTaParser.query(d, "FontSize");

            if (d.ContainsKey("FauxBold"))
            {
                FauxBold = TdTaParser.getBool(d, "FauxBold");
            }
            if (d.ContainsKey("FauxItalic"))
            {
                FauxItalic = TdTaParser.getBool(d, "FauxItalic");
            }
            if (d.ContainsKey("Underline"))
            {
                Underline = TdTaParser.getBool(d, "Underline");
            }
            if (d.ContainsKey("StyleRunAlignment"))
            {
                int styleRunAlignment = (int)TdTaParser.query(d, "StyleRunAlignment");//No idea what this maps to.
            }

            FillColor = Color.black;
            if (d.ContainsKey("FillColor"))
            {
                FillColor = TdTaParser.getColor(d, "FillColor");
            }
            if (d.ContainsKey("OutlineWidth"))
            {
                OutlineWidth = (double)TdTaParser.query(d, "OutlineWidth");
            }
            if (d.ContainsKey("StrokeFlag"))
            {
                StrokeFlag = TdTaParser.getBool(d, "StrokeFlag");
            }
            if (d.ContainsKey("StrokeColor"))
            {
                StrokeColor = TdTaParser.getColor(d, "StrokeColor");
            }

            if (d.ContainsKey("Strikethrough"))
            {
                Strikethrough = TdTaParser.getBool(d, "Strikethrough");
            }
            if (d.ContainsKey("FontBaseline"))
            {
                FontBaseline = TdTaParser.getIntger(d, "FontBaseline");
            }

            //Fix newlines
            try
            {
                //Remove MT
                if (FontName.EndsWith("MT"))
                {
                    FontName = FontName.Substring(0, FontName.Length - 2);
                }
                //Remove -Bold, -Italic, -BoldItalic
                if (FontName.EndsWith("-Bold", StringComparison.OrdinalIgnoreCase))
                {
                    Style |= FontStyle.Bold;
                }
                if (FontName.EndsWith("-Italic", StringComparison.OrdinalIgnoreCase))
                {
                    Style |= FontStyle.Italic;
                }
                if (FontName.EndsWith("-BoldItalic", StringComparison.OrdinalIgnoreCase))
                {
                    Style |= FontStyle.Bold | FontStyle.Italic;
                }
                //Remove from FontName
                FontName = new Regex("\\-(Bold|Italic|BoldItalic)$", RegexOptions.IgnoreCase | RegexOptions.IgnoreCase).Replace(FontName, "");
                //Remove PS
                if (FontName.EndsWith("PS"))
                {
                    FontName = FontName.Substring(0, FontName.Length - 2);
                }
                //Find font family

                if (FauxBold)
                {
                    Style |= FontStyle.Bold;
                }
                if (FauxItalic)
                {
                    Style |= FontStyle.Italic;
                }
                //                    if (underline) style |= FontStyle.Underline;
                //                    if (strikethrough) style |= FontStyle.Strikeout;
            }
            finally
            {
            }
        }