/// <summary>
 /// Background task work method.
 /// </summary>
 private void DoPrepareSvg(object sender, DoWorkEventArgs e)
 {
     // Lock to allow only one of these operations at a time.
     lock (_updateLock)
     {
         KanjiDao dao = new KanjiDao();
         // Get the kanji strokes.
         KanjiStrokes strokes = dao.GetKanjiStrokes(_kanjiEntity.DbKanji.ID);
         if (strokes != null && strokes.FramesSvg.Length > 0)
         {
             // If the strokes was successfuly retrieved, we have to read the compressed SVG contained inside.
             string svgString = StringCompressionHelper.Unzip(strokes.FramesSvg);
             StrokesCount = Regex.Matches(svgString, "<circle").Count;
             DispatcherHelper.Invoke(() =>
             {
                 StrokesImage = new Avalonia.Svg.Skia.SvgImage
                 {
                     Source = new SvgSource {
                         Picture = new SKSvg().FromSvg(svgString)
                     }
                 };
                 SetCurrentStroke(1);
             });
         }
     }
 }
示例#2
0
 /// <summary>
 /// Background task work method.
 /// </summary>
 private void DoPrepareSvg(object sender, DoWorkEventArgs e)
 {
     // Lock to allow only one of these operations at a time.
     lock (_updateLock)
     {
         KanjiDao dao = new KanjiDao();
         // Get the kanji strokes.
         KanjiStrokes strokes = dao.GetKanjiStrokes(_kanjiEntity.DbKanji.ID);
         if (strokes != null && strokes.FramesSvg.Length > 0)
         {
             // If the strokes was successfuly retrieved, we have to read the compressed SVG contained inside.
             SharpVectors.Renderers.Wpf.WpfDrawingSettings settings = new SharpVectors.Renderers.Wpf.WpfDrawingSettings();
             using (FileSvgReader r = new FileSvgReader(settings))
             {
                 // Unzip the stream and remove instances of "px" that are problematic for SharpVectors.
                 string svgString = StringCompressionHelper.Unzip(strokes.FramesSvg);
                 svgString    = svgString.Replace("px", string.Empty);
                 StrokesCount = Regex.Matches(svgString, "<circle").Count;
                 using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(svgString)))
                 {
                     // Then read the stream to a DrawingGroup.
                     // We are forced to do this operation on the UI thread because DrawingGroups must
                     // be always manipulated by the same thread.
                     DispatcherHelper.Invoke(() =>
                     {
                         StrokesDrawingGroup = r.Read(stream);
                         SetCurrentStroke(1);
                     });
                 }
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Attempts to retrieve the kanji strokes SVG matching the given kanji inside the zip file.
        /// </summary>
        /// <param name="k">Target kanji.</param>
        /// <returns>A kanji strokes entity, never null, that contains either the retrieved data or an
        /// empty byte array when the entry was not found.</returns>
        private KanjiStrokes RetrieveSvg(KanjiEntity k)
        {
            KanjiStrokes strokes = new KanjiStrokes();

            strokes.FramesSvg = new byte[0];

            if (!k.UnicodeValue.HasValue)
            {
                return(strokes);
            }

            ZipArchive      svgZip    = GetSvgZipArchive();
            string          entryName = string.Format("{0}_frames.svg", k.UnicodeValue.Value);
            ZipArchiveEntry entry     = svgZip.GetEntry(entryName);

            if (entry != null)
            {
                using (Stream stream = entry.Open())
                {
                    strokes.FramesSvg = StringCompressionHelper.Zip(StreamHelper.ReadToEnd(stream));
                    StringCompressionHelper.Unzip(strokes.FramesSvg);
                }
            }

            return(strokes);
        }
示例#4
0
文件: MapData.cs 项目: realtics/team4
        void WriteTileSave(object data, string key, ESaveType index)
        {
            string dataStr = JsonConvert.SerializeObject(data);

            PlayerPrefs.SetString(key, dataStr);
            string compressStr = StringCompressionHelper.Compress(dataStr);

            if (NetworkManager.Instance != null)
            {
                NetworkManager.Instance.SendFarmSaveData(index, compressStr);
            }
        }