Ejemplo n.º 1
0
 public void Save(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback, bool rememberToken)
 {
     using (Surface scratch = new Surface(input.Width, input.Height))
     {
         Save(input, output, token, callback, rememberToken);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Because the old OnSave() method is obsolete, we must use reflection to call it.
        /// This is important for legacy FileType plugins. It allows us to ensure that no
        /// new plugins can be compiled using the old OnSave() overload.
        /// </summary>
        private void OldOnSaveTrampoline(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback)
        {
            MethodInfo onSave = GetType().GetMethod(
                "OnSave",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy,
                Type.DefaultBinder,
                new Type[]
            {
                typeof(Document),
                typeof(Stream),
                typeof(SaveConfigToken),
                typeof(ProgressEventHandler)
            },
                null);

            onSave.Invoke(
                this,
                new object[]
            {
                input,
                output,
                token,
                callback
            });
        }
Ejemplo n.º 3
0
 public void Save(Stream dstStream, Document srcDocument, FileType dstFileType, SaveConfigToken parameters, Surface saveScratchSurface)
 {
     this.document        = srcDocument;
     this.fileType        = dstFileType;
     this.stream          = dstStream;
     this.saveConfigToken = parameters;
     this.scratchSurface  = saveScratchSurface;
     DialogResult dr = this.ShowDialog(false, !dstFileType.SavesWithProgress, new ThreadStart(SaveCallback));
 }
Ejemplo n.º 4
0
 protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     if (callback == null)
     {
         input.SaveToStream(output);
     }
     else
     {
         UpdateProgressTranslator upt = new UpdateProgressTranslator(ApproximateMaxOutputOffset(input), callback);
         input.SaveToStream(output, new IOEventHandler(upt.IOEventHandler));
     }
 }
Ejemplo n.º 5
0
        public SaveConfigToken GetLastSaveConfigToken()
        {
            Type            ourType         = this.GetType();
            string          savedTokenName  = "SaveConfigToken." + ourType.Namespace + "." + ourType.Name + ".BinaryFormatter";
            string          savedToken      = Settings.CurrentUser.GetString(savedTokenName, null);
            SaveConfigToken saveConfigToken = null;

            if (savedToken != null)
            {
                try
                {
                    byte[] bytes = Convert.FromBase64String(savedToken);

                    MemoryStream ms = new MemoryStream(bytes);

                    BinaryFormatter   formatter        = new BinaryFormatter();
                    DeferredFormatter deferred         = new DeferredFormatter();
                    StreamingContext  streamingContext = new StreamingContext(formatter.Context.State, deferred);
                    formatter.Context = streamingContext;

                    SerializationFallbackBinder sfb = new SerializationFallbackBinder();
                    sfb.AddAssembly(this.GetType().Assembly);
                    sfb.AddAssembly(typeof(FileType).Assembly);
                    formatter.Binder = sfb;

                    object obj = formatter.Deserialize(ms);
                    deferred.FinishDeserialization(ms);

                    ms.Close();
                    ms = null;

                    //SaveConfigToken sct = new SaveConfigToken();
                    //saveConfigToken = (SaveConfigToken)obj;
                    saveConfigToken = GetSaveConfigTokenFromSerializablePortion(obj);
                }

                catch (Exception)
                {
                    // Ignore erros and revert to default
                    saveConfigToken = null;
                }
            }

            if (saveConfigToken == null)
            {
                saveConfigToken = CreateDefaultSaveConfigToken();
            }

            return(saveConfigToken);
        }
Ejemplo n.º 6
0
 protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     GdiPlusFileType.Save(input, output, scratchSurface, this.ImageFormat, callback);
 }
Ejemplo n.º 7
0
 protected override sealed void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     OnSaveT(input, output, (TToken)token, scratchSurface, callback);
 }
Ejemplo n.º 8
0
 protected override sealed object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token)
 {
     return(GetSerializablePortionOfSaveConfigToken((TToken)token));
 }
Ejemplo n.º 9
0
        public void Save(
            Document input,
            Stream output,
            SaveConfigToken token,
            Surface scratchSurface,
            ProgressEventHandler callback,
            bool rememberToken)
        {
            Tracing.LogFeature("Save(" + GetType().FullName + ")");

            if (!this.SupportsSaving)
            {
                throw new NotImplementedException("Saving is not supported by this FileType");
            }
            else
            {
                Surface disposeMe = null;

                if (scratchSurface == null)
                {
                    disposeMe      = new Surface(input.Size);
                    scratchSurface = disposeMe;
                }
                else if (scratchSurface.Size != input.Size)
                {
                    throw new ArgumentException("scratchSurface.Size must equal input.Size");
                }

                if (rememberToken)
                {
                    Type   ourType        = this.GetType();
                    string savedTokenName = "SaveConfigToken." + ourType.Namespace + "." + ourType.Name + ".BinaryFormatter";

                    MemoryStream ms = new MemoryStream();

                    BinaryFormatter   formatter         = new BinaryFormatter();
                    DeferredFormatter deferredFormatter = new DeferredFormatter(false, null);
                    StreamingContext  streamingContext  = new StreamingContext(formatter.Context.State, deferredFormatter);
                    formatter.Context = streamingContext;

                    object tokenSubset = GetSerializablePortionOfSaveConfigToken(token);

                    formatter.Serialize(ms, tokenSubset);
                    deferredFormatter.FinishSerialization(ms);

                    byte[] bytes       = ms.GetBuffer();
                    string base64Bytes = Convert.ToBase64String(bytes);

                    Settings.CurrentUser.SetString(savedTokenName, base64Bytes);
                }

                try
                {
                    OnSave(input, output, token, scratchSurface, callback);
                }

                catch (OnSaveNotImplementedException)
                {
                    OldOnSaveTrampoline(input, output, token, callback);
                }

                if (disposeMe != null)
                {
                    disposeMe.Dispose();
                    disposeMe = null;
                }
            }
        }
Ejemplo n.º 10
0
 public override sealed bool IsReflexive(SaveConfigToken token)
 {
     return(IsReflexive((TToken)token));
 }
Ejemplo n.º 11
0
 private void DefaultsButton_Click(object sender, System.EventArgs e)
 {
     this.SaveConfigToken = this.FileType.CreateDefaultSaveConfigToken();
 }
Ejemplo n.º 12
0
 protected override sealed void InitWidgetFromToken(SaveConfigToken sourceToken)
 {
     InitWidgetFromToken((TToken)sourceToken);
 }
Ejemplo n.º 13
0
 protected virtual object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token)
 {
     return(token);
 }
Ejemplo n.º 14
0
 public override bool IsReflexive(SaveConfigToken token)
 {
     return(true);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Determines if saving with a given SaveConfigToken would alter the image
 /// in any way. Put another way, if the document is saved with these settings
 /// and then immediately loaded, would it have exactly the same pixel values?
 /// Any lossy codec should return 'false'.
 /// This value is used to optimizing preview rendering memory usage, and as such
 /// flattening should not be taken in to consideration. For example, the codec
 /// for PNG returns true, even though it flattens the image.
 /// </summary>
 /// <param name="token">The SaveConfigToken to determine reflexiveness for.</param>
 /// <returns>true if the save would be reflexive, false if not</returns>
 /// <remarks>If the SaveConfigToken is for another FileType, the result is undefined.</remarks>
 public virtual bool IsReflexive(SaveConfigToken token)
 {
     return(false);
 }
Ejemplo n.º 16
0
 protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     throw new OnSaveNotImplementedException("Derived classes must implement this method. It is virtual instead of abstract in order to maintain compatibility with legacy plugins.");
 }
Ejemplo n.º 17
0
 protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback)
 {
 }
Ejemplo n.º 18
0
 protected SaveConfigToken(SaveConfigToken copyMe)
 {
 }
Ejemplo n.º 19
0
 /// <summary>
 /// This method must be overridden in derived classes.
 /// In this method you must take the values from the given EffectToken
 /// and use them to properly initialize the dialog's user interface elements.
 /// </summary>
 protected virtual void InitWidgetFromToken(SaveConfigToken sourceToken)
 {
     //throw new InvalidOperationException("InitWidgetFromToken was not implemented, or the derived method called the base method");
 }