예제 #1
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");
        }
예제 #2
0
        public static DynVal ReadValue(BinaryReverseReader r, bool skipKey)
        {
            DynVal vt = new DynVal();

            if (!skipKey)
            {
                vt.Name = GetMeaningOfFourCC(ReadSpecialString(r));
            }

            //TODO: should be assigned a sequential number?
            vt.Type = parseTypeString(new string(r.ReadPSDChars(4)));
            switch (vt.Type)
            {
            case  OSType.tdta:

                uint       unknown = r.ReadUInt32();
                TdTaParser p       = new TdTaParser(r);
                object     o       = p.ParseOneTree();
                vt.Value = o;

                break;

            case  OSType.Descriptor:
                vt = DynVal.ReadDescriptor(r);
                break;

            case OSType.List:
                vt.Children = ReadValues(r, true);
                break;

            case OSType.Double:
                vt.Value = r.ReadDouble();
                break;

            case OSType.UnitFloat:                                              //Unif float
                //TODO: need a specific type for this, with a double and a type (percent/pixel)?
                string tst = GetMeaningOfFourCC(new string(r.ReadPSDChars(4))); //#Prc #Pxl #Ang = percent / pixels / angle?
                double d   = r.ReadDouble();
                tst     += ": " + d;
                vt.Value = tst;
                break;

            case OSType.Enumerated:
                string namesp = ReadSpecialString(r);
                string item   = ReadSpecialString(r);
                //vt.Value = namesp + "." + item; //TODO: cast to real enum
                vt.Value = GetMeaningOfFourCC(namesp) + "." + GetMeaningOfFourCC(item);
                break;

            case OSType.Integer:
                vt.Value = r.ReadInt32();     //4 byte integer
                break;

            case OSType.Boolean:
                vt.Value = r.ReadBoolean();
                break;

            case  OSType.String:
                vt.Value = r.ReadPSDUnicodeString();
                break;

            default:
                throw new Exception("Unhandled type: " + vt.Type);
            }
            return(vt);
        }
예제 #3
0
        public static DynVal ReadValue(PsdBinaryReader r, bool skipKey)
        {
            DynVal vt = new DynVal();

            if (!skipKey)
            {
                vt.Name = GetMeaningOfFourCC(ReadSpecialString(r));
            }

            //TODO: should be assigned a sequential number?
            vt.Type = parseTypeString(r.ReadAsciiChars(4));
            switch (vt.Type)
            {
            case OSType.tdta:
                // unknown
                r.ReadUInt32();
                TdTaParser p = new TdTaParser(r);
                object     o = p.ParseOneTree();
                vt.Value = o;

                break;

            case OSType.Reference:
                vt.References = ReadValues(r, true);
                break;

            case OSType.Descriptor:
                vt.Value = DynVal.ReadDescriptor(r);
                break;

            case OSType.List:
                vt.Children = ReadValues(r, true);
                break;

            case OSType.Double:
                vt.Value = r.ReadDouble();
                break;

            case OSType.UnitFloat:                                    //Unif float
                string tst = GetMeaningOfFourCC(r.ReadAsciiChars(4)); //#Prc #Pxl #Ang = percent / pixels / angle?
                double d   = r.ReadDouble();
                tst     += ": " + d;
                vt.Value = tst;
                break;

            case OSType.Enumerated:
                string typeID  = ReadSpecialString(r);
                string enumVal = ReadSpecialString(r);
                vt.Value = GetMeaningOfFourCC(typeID) + "." + GetMeaningOfFourCC(enumVal);
                break;

            case OSType.Integer:
                vt.Value = r.ReadInt32();     //4 byte integer
                break;

            case OSType.Boolean:
                vt.Value = r.ReadBoolean();
                break;

            case OSType.String:
                vt.Value = r.ReadUnicodeString();    //r.ReadPSDUnicodeString();
                break;

            case OSType.LargeInteger:
                vt.Value = r.ReadInt64();
                break;

            case OSType.Class:
                vt.Value = ReadClass(r);
                break;

            case OSType.Alias:
                vt.Value = ReadAlias(r);
                break;

            case OSType.PropertyRef:
                vt.Value = ReadProperty(r);
                break;

            case OSType.EnumeratedRef:
                vt.Value = ReadEnumeratedRef(r);
                break;

            case OSType.OffestRef:
                vt.Value = ReadOffset(r);
                break;

            case OSType.IdentifierRef:
                vt.Value = r.ReadAsciiChars(4);
                break;

            case OSType.IndexRef:
                vt.Value = r.ReadUInt16();
                break;

            case OSType.NameRef:
                vt.Value = r.ReadAsciiChars(4);
                break;

            default:
                throw new Exception("Unhandled type: " + vt.Type);
            }
            return(vt);
        }
예제 #4
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
            {
            }
        }