public void ShouldReturnValueIfKeyIsInDictionary() { // Given var dictionary = new Dictionary<int, string> {{1, "a"}, {2, "b"}}; // When / Then dictionary.FindValue(1).Should().Be("a"); dictionary.FindValue(2).Should().Be("b"); }
public static void Execute() { using (var vmClient = new VmClient()) using (var mouseClient = new MouseClient(VmIp)) { var printIndex = new Dictionary<ScreenPrint, int>(); for (;;) { var bmp = GetScreenImage(vmClient.GameScreenRect); var img = bmp.ToIplImage(); var vBmp = new Mat(img, false).CvtColor(ColorConversion.RgbToHsv).Split()[2]; //vBmp.ToBitmap().Save("v.png"); //vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(16, 16)).ToBitmap().Save("v.16.png"); //vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(128, 128)).ToBitmap().Save("v.128.png"); var small = vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(4, 4)); //Console.WriteLine(small.ElemSize()); //Console.WriteLine(vBmp.ElemSize()); //return; var print = new ScreenPrint(ColorCut(ToByteArray(small))); var index = printIndex.FindValue(print); if (index == null) { index = (printIndex.Count > 0 ? printIndex.Values.Max() : 0) + 1; printIndex[print] = index.Value; } Console.WriteLine(index); GC.Collect(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); } } }
public void ShouldReturnNullIfKeyIsNotDictionary() { // Given var dictionary = new Dictionary<int, string> {{1, "a"}}; // When / Then dictionary.FindValue(2).Should().BeNull(); }
/// <summary> /// Get object subtype from dictionary /// </summary> /// <returns>Subtype</returns> public string ObjectSubtypeToString() { // not dictionary nor stream if (ObjectType != ObjectType.Dictionary && ObjectType != ObjectType.Stream) { return(null); } return(Dictionary.FindValue("/Subtype").ToName); }
public static void Test() { Dictionary dc = new Dictionary(); dc.AddValues(); Console.WriteLine("Smith? " + dc.CheckKey("Smith")); Console.WriteLine("9999? " + dc.CheckValue("9999")); Console.WriteLine("Key: Smith, Value:" + dc.FindValue("Smith")); dc.ListElements(); }
public IEnumerable <Type> Browse(Type root, int maxLevel = 5) { var types = new Dictionary <Type, int>(); var sequences = new Queue <Type>(); sequences.Enqueue(root); types[root] = 0; for (; sequences.Any();) { var type = sequences.Dequeue(); var level = types.FindValue(type).OrDefault(0); if (level >= maxLevel) { continue; } var refs = Type_References.Find(type); foreach (var property in Sync(Childs(type))) { var child = property.ReducedType; if (types.FindValue(child) != null) { continue; } if (IsPrimitiveType(child)) { continue; } if (refs.Find(property.Name) != null) { continue; } sequences.Enqueue(child); types[child] = level + 1; } } return(types.Keys.ToArray()); }
public static ModelTransform ReadMT(this Dictionary <string, object> Dict, string Temp) { ModelTransform MT = new ModelTransform(); Dict.FindValue(out MT.BinOffset, Temp + MTBO); MT.Rot = Dict.ReadVec3(Temp + "rot" + d); MT.Scale = Dict.ReadVec3(Temp + "scale" + d); MT.Trans = Dict.ReadVec3(Temp + "trans" + d); MT.Visibility = Dict.ReadKey(Temp + "visibility" + d); return(MT); }
public ModuleDefaults Parse([CanBeNull] Dictionary <object, object> defaultsContents) { if (defaultsContents == null) { return(null); } var installSection = defaultsContents.FindValue("install"); var artifactsSection = defaultsContents.FindValue("artifacts"); try { var installData = installSectionParser.Parse(installSection, artifactsSection); var hooksData = hooksSectionParser.Parse(defaultsContents.FindValue("hooks")); var settingsData = settingsSectionParser.Parse(defaultsContents.FindValue("settings")); var buildData = buildSectionParser.ParseDefaults(defaultsContents.FindValue("build")); var depsSection = depsSectionParser.Parse(defaultsContents.FindValue("deps")); return(new ModuleDefaults { BuildSection = buildData, DepsSection = depsSection, InstallSection = installData, SettingsSection = settingsData, HooksSection = hooksData }); } catch (BadYamlException ex) { throw new BadYamlException("default." + ex.SectionName, ex.Message); } }
public ConfigSection Parse(string title, Dictionary <object, object> data, ModuleDefaults yamlDefaults) { var configSectionTitle = configSectionTitleParser.Parse(title); var installSection = data?.FindValue("install"); var artifactsSection = data?.FindValue("artifacts"); var installData = installSectionParser.Parse(installSection, artifactsSection, yamlDefaults?.InstallSection?.CurrentConfigurationInstallFiles); var depsData = data?.FindValue("deps"); var depsSection = depsSectionParser.Parse(depsData, yamlDefaults); var buildSection = data?.FindValue("build"); var buildData = buildSectionParser.ParseConfiguration(buildSection, yamlDefaults?.BuildSection); return(new ConfigSection() { Title = configSectionTitle, DepsSection = depsSection, InstallSection = installData, BuildSection = buildData }); }
public void BINReader(string file) { Dictionary <string, object> dict = new Dictionary <string, object>(); string[] dataArray; _IO = File.OpenReader(file + ".bin"); _IO.Format = Format.F; int signature = _IO.RI32(); if (signature != 0x44334123) { return; } signature = _IO.RI32(); if (signature != 0x5F5F5F41) { return; } _IO.RI64(); string[] strData = _IO.RS(_IO.L - _IO.P).Replace("\r", "").Split('\n'); for (i = 0; i < strData.Length; i++) { dataArray = strData[i].Split('='); if (dataArray.Length == 2) { dict.GetDictionary(dataArray[0], dataArray[1]); } } if (dict.FindValue(out string value, "category.length")) { Category = new string[int.Parse(value)]; for (i = 0; i < Category.Length; i++) { if (dict.FindValue(out value, "category." + i + ".value")) { Category[i] = value; } } } if (dict.FindValue(out value, "uid.length")) { UIDs = new UID[int.Parse(value)]; for (i = 0; i < UIDs.Length; i++) { dict.FindValue(out UIDs[i].Category, "uid." + i + ".category"); dict.FindValue(out UIDs[i].OrgUid, "uid." + i + ".org_uid"); dict.FindValue(out UIDs[i].Size, "uid." + i + ".size"); dict.FindValue(out UIDs[i].Value, "uid." + i + ".value"); } } _IO.C(); }
public void BINReader(string file) { Dictionary <string, object> Dict = new Dictionary <string, object>(); string[] dataArray; IO = File.OpenReader(file + ".bin"); IO.Format = Main.Format.F; Signature = IO.ReadInt32(); if (Signature != 0x44334123) { return; } Signature = IO.ReadInt32(); if (Signature != 0x5F5F5F41) { return; } IO.ReadInt64(); string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n'); for (int i = 0; i < STRData.Length; i++) { dataArray = STRData[i].Split('='); if (dataArray.Length == 2) { Dict.GetDictionary(dataArray[0], dataArray[1]); } } if (Dict.FindValue(out string value, "category.length")) { Category = new string[int.Parse(value)]; for (int i0 = 0; i0 < Category.Length; i0++) { if (Dict.FindValue(out value, "category." + i0 + ".value")) { Category[i0] = value; } } } if (Dict.FindValue(out value, "uid.length")) { _UID = new UID[int.Parse(value)]; for (int i0 = 0; i0 < _UID.Length; i0++) { Dict.FindValue(out _UID[i0].Category, "uid." + i0 + ".category"); Dict.FindValue(out _UID[i0].OrgUid, "uid." + i0 + ".org_uid"); Dict.FindValue(out _UID[i0].Size, "uid." + i0 + ".size"); Dict.FindValue(out _UID[i0].Value, "uid." + i0 + ".value"); } } IO.Close(); }
//////////////////////////////////////////////////////////////////// // Get filter names //////////////////////////////////////////////////////////////////// internal string[] GetFilterNameArray() { // look for filter PdfBase Filter = Dictionary.FindValue("/Filter"); // no filter if (Filter.IsEmpty) { return(null); } // one filter name if (Filter.IsName) { string[] FilterNameArray = new string[1]; FilterNameArray[0] = ((PdfName)Filter).NameValue; return(FilterNameArray); } // array of filters if (Filter.IsArray) { // filter name items PdfBase[] FilterNames = ((PdfArray)Filter).ArrayItems; string[] FilterNameArray = new string[FilterNames.Length]; // loop for each filter int Index; for (Index = 0; Index < FilterNames.Length; Index++) { if (!FilterNames[Index].IsName) { break; } FilterNameArray[Index] = ((PdfName)FilterNames[Index]).NameValue; } if (Index == FilterNames.Length) { return(FilterNameArray); } } // filter is in error throw new ApplicationException("/Filter nust be a name or an array of names"); }
public static void Execute() { using (var vmClient = new VmClient()) using (var mouseClient = new MouseClient(VmIp)) { var printIndex = new Dictionary <ScreenPrint, int>(); int?prev = null; for (;;) { var bmp = GetScreenImage(vmClient.GameScreenRect); var img = bmp.ToIplImage(); var vBmp = new Mat(img, false).CvtColor(ColorConversion.RgbToHsv).Split()[2]; //vBmp.ToBitmap().Save("v.png"); //vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(16, 16)).ToBitmap().Save("v.16.png"); //vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(128, 128)).ToBitmap().Save("v.128.png"); var small = vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(4, 4)); //Console.WriteLine(small.ElemSize()); //Console.WriteLine(vBmp.ElemSize()); //return; var print = new ScreenPrint(ColorCut(ToByteArray(small))); var index = printIndex.FindValue(print); if (index == null) { index = (printIndex.Count > 0 ? printIndex.Values.Max() : 0) + 1; printIndex[print] = index.Value; } if (prev != index) { Console.WriteLine(index); } prev = index; GC.Collect(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.1)); } } }
private TOut ConvertOut(TIn v) { return(_conversionHistory.FindValue(v).Value.Key); }
public static GameObject CreateMeshObject(string path, string shader = "Physical") { var obj = importedObjects.FindValue((i) => i.Path == path); if (obj == null) { var imp = MMW.GetSupportedImporter(path); obj = imp.Import(path, Importers.ImportType.Full)[0]; if (obj.Textures != null) { foreach (var tex in obj.Textures) { if (tex != null) { tex.Load(); } } } if (obj.Meshes != null) { foreach (var mesh in obj.Meshes) { if (mesh != null) { mesh.Load(); } } } importedObjects.Add(path, obj); } var sh = MMW.GetAsset <Shader>(shader); if (sh == null) { sh = MMW.GetAsset <Shader>("Error"); } foreach (var mat in obj.Materials) { mat.Shader = sh; } var go = new GameObject(obj.Name); // bone if (obj.Bones != null && obj.Bones.Length > 0) { CreateBoneObject(go.Transform, new Bone[] { obj.Bones[0] }); } if (obj.Meshes != null) { for (var i = 0; i < obj.Meshes.Length; i++) { var mr = go.AddComponent <MeshRenderer>(); mr.Bones = obj.Bones; mr.Mesh = obj.Meshes[i]; for (var m = 0; m < mr.Mesh.SubMeshCount; m++) { var matIndex = mr.Mesh.GetMaterialIndex(m); mr.SetMaterial(matIndex, obj.Materials[matIndex], false); } } } if (obj.Morphs != null) { var morpher = go.AddComponent <ComputeMorpher>(); foreach (var m in obj.Morphs) { if (m == null) { continue; } morpher.AddMorph(m.Name, m); } } return(go); }
//////////////////////////////////////////////////////////////////// // Read object //////////////////////////////////////////////////////////////////// internal void ReadObject() { // skip if done already or child of object stream if (ObjectType != ObjectType.Free || ParentObjectNo != 0) { return; } // set file position Reader.SetFilePosition(FilePosition); // read first byte Reader.ParseFile.ReadFirstChar(); // first token must be object number "nnn 0 obj" if (Reader.ParseFile.ParseObjectRefNo() != ObjectNumber) { throw new ApplicationException("Reading object header failed"); } // read next token Value = Reader.ParseFile.ParseNextItem(); // we have a dictionary if (Value.IsDictionary) { // set object value type to dictionary ObjectType = ObjectType.Dictionary; Dictionary = (PdfDictionary)Value; Value = null; // set object type if available in the dictionary string ObjectTypeStr = Dictionary.FindValue("/Type").ToName; // set special object if (ObjectTypeStr != null) { _PdfObjectType = ObjectTypeStr; } // read next token after the dictionary KeyWord KeyWord = Reader.ParseFile.ParseNextItem().ToKeyWord; // test for stream (change object from dictionary to stream) if (KeyWord == KeyWord.Stream) { // set object value type to stream ObjectType = ObjectType.Stream; // save start of stream position StreamFilePosition = Reader.GetFilePosition(); } // if it is no stream test for endobj else if (KeyWord != KeyWord.EndObj) { throw new ApplicationException("'endobj' token is missing"); } } // object is not a dictionary and not a sream else { ObjectType = ObjectType.Other; // test for endobj if (Reader.ParseFile.ParseNextItem().ToKeyWord != KeyWord.EndObj) { throw new ApplicationException("'endobj' token is missing"); } } // exit return; }
/// <summary> /// Apply predictor decode /// </summary> /// <param name="InputBuffer">Input buffer</param> /// <returns>Output buffer</returns> internal byte[] PredictorDecode ( byte[] InputBuffer ) { // test for /DecodeParams PdfDictionary DecodeParms = Dictionary.FindValue("/DecodeParms").ToDictionary; // none found if (DecodeParms == null) { return(InputBuffer); } // look for predictor code. if default (none or 1) do nothing if (!DecodeParms.FindValue("/Predictor").GetInteger(out int Predictor) || Predictor == 1) { return(InputBuffer); } // we only support predictor code 12 if (Predictor != 12) { return(null); } // get width DecodeParms.FindValue("/Columns").GetInteger(out int Width); if (Width < 0) { throw new ApplicationException("/DecodeParms /Columns is negative"); } if (Width == 0) { Width = 1; } // calculate rows int Rows = InputBuffer.Length / (Width + 1); if (Rows < 1) { throw new ApplicationException("/DecodeParms /Columns is greater than stream length"); } // create output buffer byte[] OutputBuffer = new byte[Rows * Width]; // reset pointers int InPtr = 1; int OutPtr = 0; int OutPrevPtr = 0; // first row (ignore filter) while (OutPtr < Width) { OutputBuffer[OutPtr++] = InputBuffer[InPtr++]; } // decode loop for (int Row = 1; Row < Rows; Row++) { // first byte is filter int Filter = InputBuffer[InPtr++]; // we support PNG filter up only if (Filter != 2) { throw new ApplicationException("/DecodeParms Only supported filter is 2"); } // convert input to output for (int Index = 0; Index < Width; Index++) { OutputBuffer[OutPtr++] = (byte)(OutputBuffer[OutPrevPtr++] + InputBuffer[InPtr++]); } } return(OutputBuffer); }
//////////////////////////////////////////////////////////////////// // process objects stream //////////////////////////////////////////////////////////////////// internal void ProcessObjectsStream() { // read decrypt and decompress the stream byte[] ByteArray = ReadStream(); ByteArray = DecompressStream(ByteArray); // get the count of objects in this cross reference object stream if (!Dictionary.FindValue("/N").GetInteger(out int ObjectCount) || ObjectCount <= 0) { throw new ApplicationException("Object stream: count (/N) is missing"); } // get first byte offset if (!Dictionary.FindValue("/First").GetInteger(out int FirstPos)) { throw new ApplicationException("Object stream: first byte offset (/First) is missing"); } // get /Extends (must be a reference) PdfBase Extends = Dictionary.FindValue("/Extends"); if (Extends.IsReference) { ParentObjectNo = ((PdfReference)Extends).ObjectNumber; } // create temp array of child objects PdfIndirectObject[] Children = new PdfIndirectObject[ObjectCount]; // read all byte offset array PdfByteArrayParser PC = new PdfByteArrayParser(Reader, ByteArray, false); PC.ReadFirstChar(); for (int Index = 0; Index < ObjectCount; Index++) { // object number if (!PC.ParseNextItem().GetInteger(out int ObjNo)) { throw new ApplicationException("Cross reference object stream: object number error"); } // object offset if (!PC.ParseNextItem().GetInteger(out int ObjPos)) { throw new ApplicationException("Cross reference object stream: object offset error"); } // find object PdfIndirectObject ReadObject = Reader.ObjectArray[ObjNo]; if (ReadObject == null) { throw new ApplicationException("Cross reference object stream: object not found"); } // object is free if (ReadObject.ObjectType == ObjectType.Free) { // save child Children[Index] = ReadObject; // save position ReadObject.FilePosition = FirstPos + ObjPos; } } // copy the object from the stream to the corresponding indirect object for (int Index = 0; Index < ObjectCount; Index++) { // shortcut PdfIndirectObject Child = Children[Index]; // object was loaded by later update if (Child == null) { continue; } PC.SetPos(Child.FilePosition); PC.ReadFirstChar(); PdfBase Obj = PC.ParseNextItem(); // we have a dictionary if (Obj.IsDictionary) { // set object value type to dictionary Child.ObjectType = ObjectType.Dictionary; Child.Dictionary = (PdfDictionary)Obj; // set object type if available in the dictionary string ObjectTypeStr = Child.Dictionary.FindValue("/Type").ToName; // set special object if (ObjectTypeStr != null) { Child._PdfObjectType = ObjectTypeStr; } } // we have other type of object // note: stream object is not allowed else { // set object value type to dictionary Child.ObjectType = ObjectType.Other; Child.Value = Obj; } } return; }
public static Key ReadKey(this Dictionary <string, object> Dict, string Temp) { Key Key = new Key(); Dict.FindValue(out Key.BinOffset, Temp + BO); Dict.FindValue(out Key.Type, Temp + "type"); if (Key.BinOffset == null && Key.Type == null) { return(null); } if (Key.Type == null) { return(Key); } if (Key.Type == 0x0000) { return(Key); } if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return(Key); } int i = 0, i0 = 0; byte i1 = 0; Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post"); Dict.FindValue(out Key.EPTypePre, Temp + "ep_type_pre"); Dict.FindValue(out Key.Length, Temp + "key.length"); Dict.FindValue(out Key.Max, Temp + "max"); if (Dict.StartsWith(Temp + "raw_data")) { Dict.FindValue(out Key.RawData.KeyType, Temp + "raw_data_key_type"); } if (Key.Length != null) { Key.Trans = new Key.Transform[(int)Key.Length]; for (i0 = 0; i0 < Key.Length; i0++) { if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data")) { Key.Trans[i0] = new Key.Transform(); dataArray = value.Replace("(", "").Replace(")", "").Split(','); Key.Trans[i0].Type = dataArray.Length - 1; Key.Trans[i0].Frame = dataArray[0].ToDouble(); Key.Trans[i0].Value = new double[Key.Trans[i0].Type]; for (i1 = 1; i1 < dataArray.Length; i1++) { Key.Trans[i0].Value[i1 - 1] = dataArray[i1].ToDouble(); } } } } else if (Key.RawData.KeyType != null) { Key.RawData = new Key.RawD(); Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type"); if (Dict.FindValue(out value, Temp + "raw_data.value_list")) { Key.RawData.ValueList = value.Split(','); } Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size"); value = ""; int DataSize = (int)Key.RawData.KeyType + 1; Key.Length = Key.RawData.ValueListSize / DataSize; Key.Trans = new Key.Transform[(int)Key.Length]; for (i = 0; i < Key.Length; i++) { Key.Trans[i].Type = (int)Key.RawData.KeyType; Key.Trans[i].Frame = Key.RawData.ValueList[i * DataSize + 0].ToDouble(); Key.Trans[i].Value = new double[Key.Trans[i0].Type]; for (i1 = 1; i1 < Key.Trans[i].Type; i1++) { Key.Trans[i].Value[i1 - 1] = Key.RawData.ValueList[i * DataSize + i1].ToDouble(); } } Key.RawData.ValueList = null; } return(Key); }
/// <summary> /// Build contents array for PdfPage /// </summary> public void BuildContentsArray() { // must be a page if (PdfObjectType != "/Page") { throw new ApplicationException("Build contents array: Object must be page"); } // get Contents dictionary value PdfBase ContentsValue = Dictionary.FindValue("/Contents"); // page is blank no contents if (ContentsValue.IsEmpty) { ContentsArray = new PdfIndirectObject[0]; return; } // test if contents value is a reference if (ContentsValue.IsReference) { // find the object with Object number PdfIndirectObject IndirectObject = Reader.ToPdfIndirectObject((PdfReference)ContentsValue); if (IndirectObject != null) { // the object is a stream return array with one contents object if (IndirectObject.ObjectType == ObjectType.Stream) { IndirectObject._PdfObjectType = "/Contents"; ContentsArray = new PdfIndirectObject[] { IndirectObject }; return; } // read object must be an array if (IndirectObject.ObjectType == ObjectType.Other) { ContentsValue = IndirectObject.Value; } } } // test if contents value is an array if (!ContentsValue.IsArray) { throw new ApplicationException("Build contents array: /Contents must be array"); } // array of reference numbers to contents objects PdfBase[] ReferenceArray = ((PdfArray)ContentsValue).ArrayItems; // create empty result list ContentsArray = new PdfIndirectObject[ReferenceArray.Length]; // verify that all array items are references to streams for (int Index = 0; Index < ReferenceArray.Length; Index++) { // shortcut PdfBase ContentsRef = ReferenceArray[Index]; // each item must be a reference if (!ContentsRef.IsReference) { throw new ApplicationException("Build contents array: Array item must be reference"); } // get read object PdfIndirectObject Contents = Reader.ToPdfIndirectObject((PdfReference)ContentsRef); // the object is not a stream if (Contents == null || Contents.ObjectType != ObjectType.Stream) { throw new ApplicationException("Build contents array: Contents must be a stream"); } // mark as page's contents Contents._PdfObjectType = "/Contents"; // add stream to the array ContentsArray[Index] = Contents; } // successful exit return; }
public Material GetMaterial(string name) { return(materials.FindValue(m => m.Name == name)); }
public static Key ReadKey(this Dictionary <string, object> Dict, string Temp) { Key Key = new Key(); Dict.FindValue(out Key.BinOffset, Temp + BO); Dict.FindValue(out Key.Type, Temp + "type"); if (Key.BinOffset == null && Key.Type == null) { return(null); } if (Key.Type == null) { return(Key); } if (Key.Type == 0x0000) { return(Key); } if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return(Key); } int i = 0, i0 = 0; Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post"); Dict.FindValue(out Key.EPTypePre, Temp + "ep_type_pre"); Dict.FindValue(out Key.Length, Temp + "key.length"); Dict.FindValue(out Key.Max, Temp + "max"); if (Dict.StartsWith(Temp + "raw_data")) { Dict.FindValue(out Key.RawData.KeyType, Temp + "raw_data_key_type"); } if (Key.Length != null) { int Type; Key.Trans = new IKeyFrame <double, double> [(int)Key.Length]; for (i0 = 0; i0 < Key.Length; i0++) { if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data")) { dataArray = value.Replace("(", "").Replace(")", "").Split(','); Type = dataArray.Length - 1; if (Type == 0) { Key.Trans[i0] = new KeyFrameT0 <double, double> { Frame = dataArray[0].ToDouble() } } ; else if (Type == 1) { Key.Trans[i0] = new KeyFrameT1 <double, double> { Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble() } } ; else if (Type == 2) { Key.Trans[i0] = new KeyFrameT2 <double, double> { Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(), Interpolation = dataArray[2].ToDouble() } } ; else if (Type == 3) { Key.Trans[i0] = new KeyFrameT3 <double, double> { Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(), Interpolation1 = dataArray[2].ToDouble(), Interpolation2 = dataArray[3].ToDouble() } } ; Key.Trans[i0] = Key.Trans[i0].Check(); } } } else if (Key.RawData.KeyType != null) { Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type"); if (Dict.FindValue(out value, Temp + "raw_data.value_list")) { Key.RawData.ValueList = value.Split(','); } Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size"); value = ""; int DS = (int)Key.RawData.KeyType + 1; Key.Length = Key.RawData.ValueListSize / DS; Key.Trans = new IKeyFrame <double, double> [(int)Key.Length]; if (Key.RawData.KeyType == 0) { for (i = 0; i < Key.Length; i++) { Key.Trans[i] = new KeyFrameT0 <double, double> { Frame = Key.RawData.ValueList[i * DS + 0].ToDouble() } } }
//////////////////////////////////////////////////////////////////// // Get stream length // Stream length might be in another indirect object // This method must run after ReadObject was run for all objects //////////////////////////////////////////////////////////////////// internal void GetStreamLength() { // get value PdfBase LengthValue = Dictionary.FindValue("/Length"); // dictionary value is reference to integer if (LengthValue.IsReference) { // get indirect object based on reference number PdfIndirectObject LengthObject = Reader.ToPdfIndirectObject((PdfReference)LengthValue); // read object type if (LengthObject != null && LengthObject.ObjectType == ObjectType.Other && LengthObject.Value.IsInteger) { StreamLength = ((PdfInteger)LengthObject.Value).IntValue; } // replace /Length in dictionary with actual value Dictionary.AddInteger("/Length", StreamLength); } // dictionary value is integer else if (LengthValue.IsInteger) { // save stream length StreamLength = ((PdfInteger)LengthValue).IntValue; } // stream is empty or stream length is in error if (StreamLength == 0) { return; } // stream might be outside file boundry // HP Scanners Scanned PDF does not conform to PDF standards // https://www.google.com/search?client=firefox-b-d&q=hp+officejet+PDF+scan+files+not+standard try { // set file position to the end of the stream Reader.SetFilePosition(StreamFilePosition + StreamLength); // verify end of stream // read first byte Reader.ParseFile.ReadFirstChar(); // test for endstream if (Reader.ParseFile.ParseNextItem().ToKeyWord != KeyWord.EndStream) { throw new ApplicationException("Endstream token missing"); } // test for endobj if (Reader.ParseFile.ParseNextItem().ToKeyWord != KeyWord.EndObj) { throw new ApplicationException("Endobj token missing"); } return; } catch { StreamLength = 0; Reader.InvalidPdfFile = true; return; } }
//////////////////////////////////////////////////////////////////// // Write indirect object to object analysis file //////////////////////////////////////////////////////////////////// internal void ObjectSummary ( OutputCtrl Ctrl ) { // write object header Ctrl.AppendMessage(string.Format("Object number: {0}", ObjectNumber)); Ctrl.AppendMessage(string.Format("Object Value Type: {0}", ObjectDescription())); Ctrl.AppendMessage(string.Format("File Position: {0} Hex: {0:X}", FilePosition)); if (ParentObjectNo != 0) { Ctrl.AppendMessage(string.Format("Parent object number: {0}", ParentObjectNo)); Ctrl.AppendMessage(string.Format("Parent object index: {0}", ParentObjectIndex)); } if (ObjectType == ObjectType.Stream) { Ctrl.AppendMessage(string.Format("Stream Position: {0} Hex: {0:X}", StreamFilePosition)); Ctrl.AppendMessage(string.Format("Stream Length: {0} Hex: {0:X}", StreamLength)); } // dictionary or stream if (ObjectType == ObjectType.Dictionary || ObjectType == ObjectType.Stream) { string ObjectTypeStr = Dictionary.FindValue("/Type").ToName; if (ObjectTypeStr == null) { ObjectTypeStr = PdfObjectType; } if (ObjectTypeStr != null) { Ctrl.AppendMessage(string.Format("Object Type: {0}", ObjectTypeStr)); } string ObjectSubtypeStr = Dictionary.FindValue("/Subtype").ToName; if (ObjectSubtypeStr != null) { Ctrl.AppendMessage(string.Format("Object Subtype: {0}", ObjectSubtypeStr)); } // write to pdf file Dictionary.ToByteArray(Ctrl); // final terminator Ctrl.AddEol(); } // object has contents that is not stream else if (ObjectType == ObjectType.Other) { // write content to pdf file Value.ToByteArray(Ctrl); // final terminator Ctrl.AddEol(); } // final terminator Ctrl.AddEol(); // return string return; }