コード例 #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 DynVal FindDynVal(string fourccName)
        {
            if (fourccName.Equals(Name))
            {
                return(this);
            }

            if (Children != null)
            {
                for (int i = 0, max = Children.Count; i < max; i++)
                {
                    DynVal child = Children[i];
                    DynVal _dyn  = child.FindDynVal(fourccName);
                    if (_dyn != null)
                    {
                        return(_dyn);
                    }
                }
            }

            if (this.Value is Dictionary <string, object> )
            {
                Dictionary <string, object> dynDic = (Dictionary <string, object>) this.Value;
                foreach (object p in dynDic.Values)
                {
                    if (p is DynVal)
                    {
                        DynVal _dyn = ((DynVal)p).FindDynVal(fourccName);
                        if (_dyn != null)
                        {
                            return(_dyn);
                        }
                    }
                }
            }
            if (this.Value is List <object> )
            {
                List <object> vs = (List <object>) this.Value;
                for (int i = 0; i < vs.Count; i++)
                {
                    if (vs[i] is DynVal)
                    {
                        DynVal _dyn = ((DynVal)vs[i]).FindDynVal(fourccName);
                        if (_dyn != null)
                        {
                            return(_dyn);
                        }
                    }
                }
            }

            if (this.Value is DynVal)
            {
                return(((DynVal)Value).FindDynVal(fourccName));
            }

            return(null);
        }
コード例 #3
0
        public static DynVal ReadAlias(PsdBinaryReader r)
        {
            DynVal v = new DynVal();

            v.Type = OSType.Alias;
            uint length = r.ReadUInt32();

            v.Value = r.ReadBytes((int)length);
            return(v);
        }
コード例 #4
0
        public static DynVal ReadClass(PsdBinaryReader r)
        {
            DynVal v = new DynVal();

            v.Type        = OSType.Class;
            v.UnicodeName = r.ReadUnicodeString();
            v.classID     = ReadSpecialString(r);
            v.Name        = GetMeaningOfFourCC(v.classID);
            return(v);
        }
コード例 #5
0
ファイル: GradientEffect.cs プロジェクト: lwx1010/2D_XProject
        private void parseColors(DynVal cols)
        {
            DynVal topDyn = cols.Children[cols.Children.Count - 1].FindDynVal("RGBC");

            TopColor = getColor(topDyn);

            DynVal bottomDyn = cols.Children[0].FindDynVal("RGBC");

            BottomColor = getColor(bottomDyn);
        }
コード例 #6
0
        public static DynVal ReadOffset(PsdBinaryReader r)
        {
            DynVal v = new DynVal();

            v.Type        = OSType.OffestRef;
            v.UnicodeName = r.ReadUnicodeString();
            v.classID     = ReadSpecialString(r);
            v.Name        = GetMeaningOfFourCC(v.classID);
            v.Value       = r.ReadUInt32();
            return(v);
        }
コード例 #7
0
        public static DynVal ReadDescriptor(BinaryReverseReader r)
        {
            DynVal v = new DynVal();

            v.UnicodeName = r.ReadPSDUnicodeString();
            v.Type        = OSType.Descriptor;
            v.classID     = ReadSpecialString(r);
            v.Name        = GetMeaningOfFourCC(v.classID);
            v.Children    = DynVal.ReadValues(r, false);
            return(v);
        }
コード例 #8
0
        public static DynVal ReadProperty(PsdBinaryReader r)
        {
            DynVal v = new DynVal();

            v.UnicodeName = r.ReadUnicodeString();//r.ReadPSDUnicodeString();
            v.Type        = OSType.PropertyRef;
            v.classID     = ReadSpecialString(r);
            v.Name        = GetMeaningOfFourCC(v.classID);
            v.KeyID       = ReadSpecialString(r);

            return(v);
        }
コード例 #9
0
ファイル: GradientEffect.cs プロジェクト: lwx1010/2D_XProject
        private Color getColor(DynVal dv)
        {
            if (dv == null)
            {
                return(Color.black);
            }

            int r = (int)(double)dv.FindDynVal("Rd").Value;
            int g = (int)(double)dv.FindDynVal("Grn").Value;
            int b = (int)(double)dv.FindDynVal("Bl").Value;

            return(Util.FromArgb(r, g, b));
        }
コード例 #10
0
        public ObjectBasedEffect(PsdBinaryReader reader, int dataLength)
        {
            uint version           = reader.ReadUInt32();
            uint descriptorVersion = reader.ReadUInt32();

            Descriptor = DynVal.ReadDescriptor(reader);

            DynVal grad = Descriptor.FindDynVal("Grad");

            if (grad != null)
            {
                Gradient = new GradientEffect();
                Gradient.ParseDescriptor(grad);
            }
        }
コード例 #11
0
        public static DynVal ReadEnumeratedRef(PsdBinaryReader r)
        {
            DynVal v = new DynVal();

            v.Type        = OSType.EnumeratedRef;
            v.UnicodeName = r.ReadUnicodeString();
            v.classID     = ReadSpecialString(r);
            v.Name        = GetMeaningOfFourCC(v.classID);

            string TypeID  = ReadSpecialString(r);
            string enumVal = ReadSpecialString(r);

            v.Value = GetMeaningOfFourCC(TypeID) + "." + GetMeaningOfFourCC(enumVal);
            return(v);
        }
コード例 #12
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);
        }
コード例 #13
0
        public TypeToolObject(PhotoshopFile.Layer.AdjustmentLayerInfo info)
        {
            this.m_data = info.Data;
            this.m_key = info.Key;
            this.m_layer = info.Layer;

            BinaryReverseReader r = this.DataReader;

            ushort PhotshopVersion = r.ReadUInt16(); //2 bytes, =1 Photoshop 6 (not 5)

            this.Transform = new Matrix2D(r); //six doubles (48 bytes)

            ushort TextVersion = r.ReadUInt16(); //2 bytes, =50. For Photoshop 6.0.
            uint DescriptorVersion = r.ReadUInt32(); //4 bytes,=16. For Photoshop 6.0.

            this.TxtDescriptor = DynVal.ReadDescriptor(r); //Text descriptor

            ushort WarpVersion = r.ReadUInt16(); //2 bytes, =1. For Photoshop 6.0.
            uint WarpDescriptorVersion = r.ReadUInt32(); //4 bytes, =16. For Photoshop 6.0.

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

            //string desc = this.TxtDescriptor.getString();

            this.WarpDescriptor = DynVal.ReadDescriptor(r); //Warp descriptor
            this.Data = r.ReadBytes((int)r.BytesToEnd); //17 bytes???? All zeroes?
            if (Data.Length != 17 || !(Array.TrueForAll(Data, b => b == 0)))
            {
                string s = ReadableBinary.CreateHexEditorString(Data);
                Debug.Write(s);
            }

            //this.WarpRect = new RectangleF();
            //WarpRect.X = (float)r.ReadDouble();
            //WarpRect.Y = (float)r.ReadDouble();
            //this.Data.
            //WarpRect.Width = (float)r.ReadDouble() - WarpRect.X;
            //WarpRect.Height = (float)r.ReadDouble() - WarpRect.Y;

            //this.Data = r.ReadBytes((int)r.BytesToEnd);
        }
コード例 #14
0
ファイル: DynVal.cs プロジェクト: stukalin/ImageResizer
        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;
        }
コード例 #15
0
ファイル: DynVal.cs プロジェクト: stukalin/ImageResizer
 public static DynVal ReadDescriptor(BinaryReverseReader r)
 {
     DynVal v = new DynVal();
     v.UnicodeName = r.ReadPSDUnicodeString();
     v.Type = OSType.Descriptor;
     v.classID = ReadSpecialString(r);
     v.Name = GetMeaningOfFourCC(v.classID);
     v.Children = DynVal.ReadValues(r, false);
     return v;
 }
コード例 #16
0
ファイル: GradientEffect.cs プロジェクト: lwx1010/2D_XProject
        public void ParseDescriptor(DynVal gradDyn)
        {
            DynVal cols = gradDyn.FindDynVal("Clrs");

            parseColors(cols);
        }
コード例 #17
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);
        }
コード例 #18
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
            {
            }
        }