示例#1
0
        /// <summary>
        /// Creates a copy of a list with the items in random order.
        /// </summary>
        /// <param name="list">
        /// The list to copy.
        /// </param>
        /// <param name="randNumGen">
        /// An object that generates random numbers.
        /// </param>
        /// <returns>
        /// A copy of the list with its items shuffled (their order in the
        /// list is random).
        /// </returns>
        public static Generic.IList <T> Shuffle <T>(Generic.IList <T> list,
                                                    System.Random randomNumGen)
        {
            if (list == null)
            {
                return(null);
            }
            Require.ArgumentNotNull(randomNumGen);

            //  List of item indexes.
            Generic.List <int> indexes = new Generic.List <int>(list.Count);
            for (int i = 0; i < list.Count; ++i)
            {
                indexes.Add(i);
            }

            Generic.List <T> shuffledList = new Generic.List <T>(list.Count);
            while (indexes.Count > 0)
            {
                //  Randomly pick a remaining item in the list
                int indexOfIndex = randomNumGen.Next(indexes.Count);
                int index        = indexes[indexOfIndex];
                indexes.RemoveAt(indexOfIndex);
                shuffledList.Add(list[index]);
            }

            return(shuffledList);
        }
示例#2
0
        /// <summary>
        /// Utility function to enable a list of LinkExtensions
        /// </summary>
        /// <param name="baseOptions"></param>
        /// <param name="linkExtensions"></param>
        /// <param name="enable"></param>
        public static void ChangeLinkExtensionEnableStatue(/*Deployment.DeploymentBaseOptions*/ dynamic baseOptions, System.Collections.Generic.List <string> linkExtensions, bool enable)
        {
            if (linkExtensions != null && linkExtensions.Count != 0)
            {
                foreach (string linkExtObj in linkExtensions)
                {
                    RegularExpressions.Regex match       = new RegularExpressions.Regex(linkExtObj, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    Generic.List <object>    matchedList = new Generic.List <object>();

                    foreach (/*Deployment.DeploymentLinkExtension*/ dynamic linkExtension in baseOptions.LinkExtensions)
                    {
                        if (match.IsMatch(linkExtension.Name))
                        {
                            matchedList.Add(linkExtension);
                        }
                    }

                    if (matchedList.Count > 0)
                    {
                        foreach (/*Deployment.DeploymentLinkExtension*/ dynamic extension in matchedList)
                        {
                            extension.Enabled = enable;
                        }
                    }
                    else
                    {
                        // throw new DeploymentException(Resources.UnknownLinkExtension, disableLink);
                        //$Todo lmchen
                        //Diagnostics.Debug.Assert(false, "NYI, we should prompt user for invalid LinkExtension");
                        throw new System.InvalidOperationException("UnknowLinkExtension");
                    }
                }
            }
        }
示例#3
0
        public void ListOfDoubles()
        {
            double[] values = new double[] {
                5.0, -4.0, 333.0, -0.2, 1
            };
            double[] expectedValues = new double[] {
                //  indexes = [0,1,2,3,4], so maxValue = 5 --> index at 2 returned
                333.0,
                //  indexes = [0,1,3,4], so maxValue = 4 --> index at 3 returned
                1,
                //  indexes = [0,1,3], so maxValue = 3 --> index at 0 returned
                5.0,
                //  indexes = [1,3], so maxValue = 2 --> index at 1 returned
                -0.2,
                //  indexes = [1], so maxValue = 1 --> index at 0 returned
                -4.0
            };

            Generic.IList <double> list         = new Generic.List <double>(values);
            Generic.IList <double> shuffledList = List.Shuffle(list,
                                                               randomNumGen);
            Assert.AreEqual(expectedValues.Length, shuffledList.Count);
            for (int i = 0; i < expectedValues.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], shuffledList[i]);
            }
        }
        /// <summary>
        /// Processing SharePoint list to add Logs to collection
        /// </summary>
        /// <param name="lists"> SharePoint list collection</param>
        /// <returns> task object</returns>
        public async Task AddListsInfo(Generic.List <List> lists)
        {
            bool skipListSeparationLine = true;
            bool addListTitle           = lists.Count > 1;

            foreach (var list in lists)
            {
                if (list.Fields.Any(field => field.Title == "File Type") &&
                    list.Fields.Any(field => field.Title == "HTML File Type"))
                {
                    if (!skipListSeparationLine)
                    {
                        Logs.Add("------------------------------------");
                    }

                    if (addListTitle)
                    {
                        Logs.Add("List: " + list.Title);
                    }

                    Logs.Add("Items Count: " + list.ItemCount);
                    await AddOneNoteItemsInfo(list);

                    AddIndexingInfo(list);
                    skipListSeparationLine = false;
                }
            }
        }
        public void ListOfDoubles()
        {
            double[] values = new double[]{
                5.0, -4.0, 333.0, -0.2, 1
            };
            double[] expectedValues = new double[]{
                //  indexes = [0,1,2,3,4], so maxValue = 5 --> index at 2 returned
                333.0,
                //  indexes = [0,1,3,4], so maxValue = 4 --> index at 3 returned
                1,
                //  indexes = [0,1,3], so maxValue = 3 --> index at 0 returned
                5.0,
                //  indexes = [1,3], so maxValue = 2 --> index at 1 returned
                -0.2,
                //  indexes = [1], so maxValue = 1 --> index at 0 returned
                -4.0
            };

            Generic.IList<double> list = new Generic.List<double>(values);
            Generic.IList<double> shuffledList = List.Shuffle(list,
                                                              randomNumGen);
            Assert.AreEqual(expectedValues.Length, shuffledList.Count);
            for (int i = 0; i < expectedValues.Length; i++)
                Assert.AreEqual(expectedValues[i], shuffledList[i]);
        }
示例#6
0
        public static int WritePages(PdfWriter w, Generic.List <PdfPage> pages)
        {
            System.Text.StringBuilder kids = new System.Text.StringBuilder();
            int pagesobj = w.AllocObj();

            foreach (PdfPage p in pages)
            {
                w.CP = p;
                w.FinishPage();
                p.EndText();

                byte[] Content    = p.OS.ToArray();
                int    contentobj = w.PutStream(Content);

                int pageobj = w.StartObj();
                kids.Append(pageobj + " 0 R ");
                w.Put("<</Type/Page/Parent " + pagesobj
                      + " 0 R/MediaBox[0 0 " + p.Layout.Width + " " + p.Layout.Height + "]/Contents " + contentobj
                      + " 0 R/Resources <<");
                PutResourceSet(w, p.Fonts, "/Font", "/F");
                PutResourceSet(w, p.Xobjs, "/XObject", "/X");
                w.Put(" >> >>");
                w.EndObj();
            }
            w.StartObj(pagesobj); w.Put("<</Type/Pages/Count " + pages.Count + "/Kids[" + kids + "]>>"); w.EndObj();
            return(pagesobj);
        }
示例#7
0
        // -- Private Methods --

        /**
         * Returns an array of all the TileMaps object under a given node.
         */
        private static Generic.List <TileMap> FindTilemapsUnder(Node root)
        {
            // Prepare the return list.
            Generic.List <TileMap> output = new Generic.List <TileMap>();

            // Loop through all the children nodes.
            foreach (Node child in root.GetChildren())
            {
                // If the object is a TileMap.
                if (child is TileMap)
                {
                    // Add it to the result list.
                    output.Add(child as TileMap);
                }

                // If the object has any children.
                if (child.GetChildCount() > 0)
                {
                    // Add its sub-tilemaps to the list.
                    output.AddRange(FindTilemapsUnder(child));
                }
            }

            // Return the list.
            return(output);
        }
示例#8
0
        /// <summary>
        /// Retrieving log info for OneNote items
        /// </summary>
        /// <param name="sender"> Sender object</param>
        /// <param name="e"> Event argument</param>
        private async void button1_Click(object sender, EventArgs e)
        {
            if (!ValidateParameters())
            {
                return;
            }
            try
            {
                DisabledControls();
                using (Utilities utilities = new Utilities(UrlText.Text, UserText.Text, PasswordText.Text))
                {
                    var list = await utilities.GetDocumentLibrary();

                    Generic.List <List> lists = new Generic.List <List>()
                    {
                        list
                    };
                    await utilities.AddListsInfo(lists);

                    StringBuilder sb = new StringBuilder();
                    utilities.Logs.ForEach(result => sb.Append(result + "\r\n"));
                    ResultText.Text = sb.ToString();
                    utilities.AddToLogFile(ResultText.Text);
                }
            }
            catch (Exception ex)
            {
                ResultText.Text = ex.ToString();
            }
            finally
            {
                EnabledControls();
            }
        }
示例#9
0
 /// <summary>
 /// Utility function to enable a list of LinkExtensions
 /// </summary>
 /// <param name="baseOptions"></param>
 /// <param name="listOfLinkExtensions"></param>
 /// <param name="enable"></param>
 public static void ChangeLinkExtensionEnableStatue(/*Deployment.DeploymentBaseOptions*/ dynamic baseOptions, string listOfLinkExtensions, bool enable)
 {
     if (!string.IsNullOrEmpty(listOfLinkExtensions))
     {
         Generic.List <string> linkExtensionList = ConvertStringIntoList(listOfLinkExtensions);
         ChangeLinkExtensionEnableStatue(baseOptions, linkExtensionList, enable);
     }
 }
示例#10
0
 /// <summary>
 /// we can't use the method of List<string>.Contains, as it is case sensitive, so have to write a separate comparison routine
 /// </summary>
 /// <param name="link"></param>
 /// <param name="linkCollection"></param>
 /// <returns></returns>
 internal static bool LinkContainedInTheCollection(string link, Generic.List <string> linkCollection)
 {
     foreach (string l in linkCollection)
     {
         if (string.Compare(l, link, System.StringComparison.OrdinalIgnoreCase) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
示例#11
0
 private static void PutResourceSet(PdfWriter w, Generic.List <int> S, String n1, String n2)
 {
     if (S.Count > 0)
     {
         w.Put(n1 + "<<"); foreach (int i in S)
         {
             w.Put(n2 + i + " " + i + " 0 R");
         }
         w.Put(">>");
     }
 }
        private async void GetInfoButton_Click(object sender, EventArgs e)
        {
            if (!ValidateParameters())
            {
                return;
            }

            try
            {
                DisabledControls();
                using (Utilities utilities = new Utilities(UrlText.Text, UserText.Text, PasswordText.Text))
                {
                    Generic.List <List> lists = null;
                    if (rdoAllList.Checked)
                    {
                        lists = await utilities.GetLists();

                        listBox.Enabled = true;
                        listBox.Items.Clear();
                        listBox.Enabled = false;
                    }
                    else
                    {
                        var list = await utilities.GetDocumentLibrary();

                        lists = new Generic.List <List>()
                        {
                            list
                        };
                    }


                    lists.ForEach(l => listBox.Items.Add(l.Title));

                    await utilities.AddListsInfo(lists);

                    StringBuilder sb = new StringBuilder();
                    utilities.Logs.ForEach(result => sb.Append(result + "\r\n"));
                    ResultText.Text = sb.ToString();
                    utilities.AddToLogFile(ResultText.Text);
                }
            }
            catch (Exception ex)
            {
                ResultText.Text = ex.ToString();
            }
            finally
            {
                EnabledControls();
            }
        }
示例#13
0
        /**
         * Returns a Rect2 containing all the tilemaps object given.
         */
        private static Rect2 GetTilemapsLimits(Generic.List <TileMap> tilemaps)
        {
            // Prepare the return rect.
            Rect2 limits = new Rect2();

            // Loop through the tilemaps.
            foreach (TileMap tilemap in tilemaps)
            {
                // Merge the rect2 objects.
                limits = limits.Merge(tilemap.GetUsedRect());
            }

            // Return the limits.
            return(limits);
        }
示例#14
0
        /// <summary>
        /// Utility function to convert a string passed in from target file into a list
        /// </summary>
        /// <param name="linkExtensionsString"></param>
        /// <returns></returns>
        internal static Generic.List <string> ConvertStringIntoList(string linkExtensionsString)
        {
            string linkExtensionsInfo = "";

            if (!string.IsNullOrEmpty(linkExtensionsString))
            {
                linkExtensionsInfo = linkExtensionsString;
                string[] linksArray             = linkExtensionsInfo.Split(new char[] { ';' });
                Generic.List <string> linksList = new Generic.List <string>(linksArray);
                return(linksList);
            }
            else
            {
                return(new System.Collections.Generic.List <string>(0));
            }
        }
示例#15
0
        protected static NamespaceCacheElement[] enumerateAncestors(NamespaceCacheElement ncElem, bool includeSelf)
        {
            Generic.List <NamespaceCacheElement> ncAncestors = new Generic.List <NamespaceCacheElement>();

            if (includeSelf)
            {
                ncAncestors.Insert(0, ncElem);
            }

            while (ncElem.Parent != null)
            {
                ncElem = ncElem.Parent;
                ncAncestors.Insert(0, ncElem);
            }

            return(ncAncestors.ToArray());
        }
        //ii.Highest Card wins
        public Generic.List <int> EvaluateWinners()
        {
            Generic.List <int> winningPlayerNumbers = new Generic.List <int>();
            Generic.List <CardGameLibrary.PlayerOfCard> highestPlayersOfCards = new Generic.List <CardGameLibrary.PlayerOfCard>();
            CardGameLibrary.PlayerOfCard highestPlayerOfCards = null;

            //Initially, assign first player as highest card winner
            if (PlayerOfCardsInGame.Count > 0)
            {
                highestPlayerOfCards = PlayerOfCardsInGame[0];
                highestPlayersOfCards.Add(highestPlayerOfCards);
            }

            for (int i = 1; i < PlayerOfCardsInGame.Count; i++)
            {
                //If previous player(s) temporarily assigned
                //as highest card winner is outranked, remove
                //and add new player as currently
                //assigned highest card winner
                if (PlayerOfCardsInGame[i].PlayerScore >
                    highestPlayerOfCards.PlayerScore)
                {
                    highestPlayersOfCards.RemoveAll
                        (match => match.PlayerScore
                        == highestPlayerOfCards.PlayerScore);
                    highestPlayerOfCards = PlayerOfCardsInGame[i];
                    highestPlayersOfCards.Add(highestPlayerOfCards);
                }
                //Multiple players having cards of same rank can be co-winners
                else if (PlayerOfCardsInGame[i].PlayerScore ==
                         highestPlayerOfCards.PlayerScore)
                {
                    highestPlayerOfCards = PlayerOfCardsInGame[i];
                    highestPlayersOfCards.Add(highestPlayerOfCards);
                }
            }

            //This should be a list of at most Count == 4 for co-winner use-cases
            foreach (CardGameLibrary.PlayerOfCard playerOfCards in highestPlayersOfCards)
            {
                winningPlayerNumbers.Add(playerOfCards.PlayerNumber);
            }

            return(winningPlayerNumbers);
        }
        private async void BuildIndexButton_Click(object sender, EventArgs e)
        {
            if (!ValidateParameters())
            {
                return;
            }

            if (listBox.SelectedItem == null)
            {
                MessageBox.Show("Select List");
                listBox.Focus();
                return;
            }
            try
            {
                DisabledControls();
                using (Utilities utilities = new Utilities(UrlText.Text, UserText.Text, PasswordText.Text))
                {
                    var lib = await utilities.GetListByTitle(listBox.SelectedItem.ToString());

                    await utilities.AddIndexOnListFields(lib);

                    lib = await utilities.GetListByTitle(listBox.SelectedItem.ToString());

                    Generic.List <List> lists = new Generic.List <List>()
                    {
                        lib
                    };
                    await utilities.AddListsInfo(lists);

                    StringBuilder sb = new StringBuilder();
                    utilities.Logs.ForEach(result => sb.Append(result + "\r\n"));
                    ResultText.Text = sb.ToString();
                    utilities.AddToLogFile(ResultText.Text);
                }
            }
            catch (Exception ex)
            {
                ResultText.Text = ex.ToString();
            }
            finally
            {
                EnabledControls();
            }
        }
示例#18
0
        static void Main(string[] args)
        {
            StandardC.ArrayList standardArrayList = new StandardC.ArrayList();
            StandardC.Hashtable standardHashtable = new StandardC.Hashtable();
            StandardC.Queue     standardQueue     = new StandardC.Queue();
            StandardC.Stack     standardStack     = new StandardC.Stack();

            Generic.Dictionary <int, string> genericDictionary = new Generic.Dictionary <int, string>();
            Generic.List <int>  genericList  = new Generic.List <int>();
            Generic.Queue <int> genericQueue = new Generic.Queue <int>();
            Generic.SortedList <int, string> genericSortedList = new Generic.SortedList <int, string>();
            Generic.Stack <int> genericStack = new Generic.Stack <int>();

            Concurrent.BlockingCollection <int>           concurrentBlockingCollection = new Concurrent.BlockingCollection <int>();
            Concurrent.ConcurrentDictionary <int, string> concurrentDictionary         = new Concurrent.ConcurrentDictionary <int, string>();
            Concurrent.ConcurrentQueue <int> concurrentQueue = new Concurrent.ConcurrentQueue <int>();
            Concurrent.ConcurrentStack <int> concurrentStack = new Concurrent.ConcurrentStack <int>();

            Console.WriteLine("Hello World!");
        }
        /// <summary>
        /// Retrieving SharePoint list collection
        /// </summary>
        /// <returns> SharePoint list collection</returns>
        public async Task <Generic.List <List> > GetLists()
        {
            Generic.List <List> resultLists = new Generic.List <List>();
            IQueryable <List>   listsWithIncludedProperty = ClientObjectQueryableExtension.Include(context.Web.Lists,
                                                                                                   list => list.Id,
                                                                                                   list => list.Title,
                                                                                                   list => list.ItemCount,
                                                                                                   list => list.Fields.Include(f => f.Title, f => f.Indexed, f => f.InternalName));

            IQueryable <List> listCollection =
                listsWithIncludedProperty.Where(list => list.BaseType == BaseType.DocumentLibrary &&
                                                (list.BaseTemplate == (int)ListTemplateType.DocumentLibrary ||
                                                 list.BaseTemplate == (int)ListTemplateType.MySiteDocumentLibrary) &&
                                                list.Hidden == false);

            Generic.IEnumerable <List> lists = context.LoadQuery(listCollection);
            await ExecuteQuery();

            lists.ForEach(list => resultLists.Add(list));
            return(resultLists);
        }
示例#20
0
        public override void Encode(string s, int start, int end, Generic.List <byte> buf)
        {
            System.Text.Encoding enc = System.Text.Encoding.GetEncoding(1252); // Not sure if this is right.
            int len  = end - start;
            int need = enc.GetMaxByteCount(len);

            if (need > EncBuffer.Length)
            {
                EncBuffer = Util.GetBuf(need);
            }
            int nb = enc.GetBytes(s, start, len, EncBuffer, 0);

            for (int i = 0; i < nb; i += 1)
            {
                byte b = EncBuffer[i];
                if (b != 10)
                {
                    buf.Add(b);
                }
            }
        }
示例#21
0
        // Encodes a string as a list of Glyph indexes.

        public override void Encode(string s, int start, int end, Generic.List <byte> buf)
        {
            for (int i = start; i < end; i += 1)
            {
                char c = s[i];
                if (c != '\n')
                {
                    int uc = c;
                    if (System.Char.IsSurrogate(c))
                    {
                        uc = char.ConvertToUtf32(s, i); i += 1;
                    }

                    int gi = XG(Index(uc));
                    if (gi >= 0) // If char not found, it is simply ignored ( in future may want a fallback mechanism ).
                    {
                        buf.Add((byte)(gi >> 8));
                        buf.Add((byte)(gi & 0xff));
                    }
                }
            }
        }
示例#22
0
        private void ResolveTokens(string s)
        {
            int index      = -1;
            int startIndex = 0;

            Generic.List <string> tokenParts = new Generic.List <string>();

            //index = s.IndexOfAny(separators, startIndex);
            while ((index = s.IndexOfAny(separators, startIndex)) > 0)
            {
                int offset = index - startIndex;
                if (offset > 0)
                {
                    tokenParts.Add(s.Substring(startIndex, index - startIndex));
                }
                tokenParts.Add(s.Substring(index, 1));

                startIndex = index + 1;
            }

            tokenParts.Add(s.Substring(startIndex));
            tokenParts.Add(string.Empty); // TODO: Simulate EOL
            tokens = tokenParts.ToArray();
        }
 public void NullRandomNumGen()
 {
     Generic.IList<byte> list = new Generic.List<byte>();
     List.Shuffle(list, null);
 }
示例#24
0
 public void NullList()
 {
     Generic.List <int> list = null;
     Assert.IsNull(List.Shuffle(list, randomNumGen));
 }
示例#25
0
 public void NullRandomNumGen()
 {
     Generic.IList <byte> list = new Generic.List <byte>();
     List.Shuffle(list, null);
 }
示例#26
0
        private short XMin, XMax, YMin, YMax; // These are calculated by GetFontBytes.

        private byte[] GetFontBytes()         // Returns the TrueType subset file as an array of bytes.
        {
            /* Tables required in theory ( those marked '?' may not actually be needed in PDF, maxp IS needed ).
             * 'cmap' character to glyph mapping (?)
             * 'glyf' glyph data
             * 'head' font header
             * 'hmtx' horizontal metrics
             * 'hhea' horizontal header
             * 'loca' index to location
             * 'maxp' maximum profile
             * 'name' naming (?)
             * 'post' PostScript (?)
             * 'OS/2' Font validator says this is a required table (?)
             */

            TrueType.Writer tw = new TrueType.Writer(7); // glyf, head, hmtx, hhea, loca, maxp

            Generic.List <uint> locations = new Generic.List <uint>();

            // Summary values for 'head' 'hhea' and 'maxp' tables calculated as 'glyp' table is written.
            XMin = 0x7fff; XMin = 0x7fff; XMax = -0x8000; YMax = -0x8000;
            int maxContours = 0, maxPoints = 0,
                maxComponentPoints = 0, maxComponentContours = 0, maxComponentDepth = 0, maxComponentElements = 0,
                xMaxExtent = 0, minRightSideBearing = 0x7fff;
            int advanceWidthMax = -0x8000, minLeftSideBearing = 0x7fff;

            // 'glyf' table
            tw.BeginTable();
            for (int gi = 0; gi < GList.Count; gi += 1)
            {
                int sgi = GList[gi];

                TrueType.Glyph g; Inp.ReadGlyph(sgi, false, out g);
                locations.Add(tw.Offset());

                TrueType.WidthInfo w; Inp.GetGlyphWidth(sgi, out w);
                if (w.AdvanceWidth > advanceWidthMax)
                {
                    advanceWidthMax = w.AdvanceWidth;
                }
                if (w.LeftSideBearing < minLeftSideBearing)
                {
                    minLeftSideBearing = w.LeftSideBearing;
                }
                if (g.XMin < XMin)
                {
                    XMin = g.XMin;
                }
                if (g.YMin < YMin)
                {
                    YMin = g.YMin;
                }
                if (g.XMax > XMax)
                {
                    XMax = g.XMax;
                }
                if (g.YMax > YMax)
                {
                    YMax = g.YMax;
                }
                int extent = w.LeftSideBearing + (g.XMax - g.XMin);
                if (extent > xMaxExtent)
                {
                    xMaxExtent = extent;
                }
                int rsb = w.AdvanceWidth - w.LeftSideBearing - (g.XMax - g.XMin);
                if (rsb < minRightSideBearing)
                {
                    minRightSideBearing = rsb;
                }

                if (g.Contours != 0)
                {
                    if (g.Contours >= 0)
                    {
                        if (g.Contours > maxContours)
                        {
                            maxContours = g.Contours;
                        }
                        if (g.Points > maxPoints)
                        {
                            maxPoints = g.Points;
                        }

                        if (KeepInstructions)
                        {
                            tw.Write(Inp.Data, g.Pos, g.Len);
                        }
                        else
                        {
                            int off = 10 + 2 * g.Contours; /* Contours .. EndPoints */
                            tw.Write(Inp.Data, g.Pos, off);
                            tw.Put16(0);
                            off += 2 + g.InstructionLen;
                            tw.Write(Inp.Data, g.Pos + off, g.Len - off);
                        }
                    }
                    else // Compound glyph
                    {
                        tw.Write(Inp.Data, g.Pos, 10);
                        for (int i = 0; i < g.Components.Count; i += 1)
                        {
                            TrueType.Component c = g.Components[i];
                            c.GlyphIx = (uint)XG((int)c.GlyphIx);
                            tw.Put(c);
                        }

                        TrueType.GlyphStats gs; Inp.GetGlyphStats(sgi, out gs);
                        if (gs.Points > maxComponentPoints)
                        {
                            maxComponentPoints = gs.Points;
                        }
                        if (gs.Contours > maxComponentContours)
                        {
                            maxComponentContours = gs.Contours;
                        }
                        if (gs.ComponentDepth > maxComponentDepth)
                        {
                            maxComponentDepth = gs.ComponentDepth;
                        }
                        // Maximum number of components referenced at “top level” for any composite glyph.
                        if (g.Components.Count > maxComponentElements)
                        {
                            maxComponentElements = g.Components.Count;                                // Not sure what "top level" means, maybe just not recursive calc?
                        }
                    }
                }
                tw.Pad(4);
            }
            locations.Add(tw.Offset()); // Additional entry so length of final glyph is represented in locations.
            tw.EndTable(TrueType.Tid.glyf);

            // 'head' table
            tw.BeginTable();
            tw.Put32(0x00010000);     // Version
            tw.Put32(0);              // fontRevision
            tw.Put32(0);              // checkSumAdjustment
            tw.Put32(0x5F0F3CF5);     // magic number
            tw.Put16(0);              // flags
            tw.Put16(Inp.UnitsPerEm); // unitsPerEm
            tw.Put64(0);              // created
            tw.Put64(0);              // modified
            unchecked
            {
                tw.Put16((ushort)XMin);
                tw.Put16((ushort)YMin);
                tw.Put16((ushort)XMax);
                tw.Put16((ushort)YMax);
            }
            tw.Put16(0); // macStyle
            tw.Put16(7); // lowestRecPPEM
            tw.Put16(2); // fontDirectionHint
            tw.Put16(1); // indexToLocFormat
            tw.Put16(0); // glyphDataFormat
            tw.EndTable(TrueType.Tid.head);

            // 'hmtx' horizontal metrics
            tw.BeginTable();
            foreach (int gi in GList)
            {
                TrueType.WidthInfo w; Inp.GetGlyphWidth(gi, out w);
                unchecked
                {
                    tw.Put16(w.AdvanceWidth);
                    tw.Put16((uint)w.LeftSideBearing);
                }
            }
            tw.EndTable(TrueType.Tid.hmtx);

            // 'hhea' horizontal header
            tw.BeginTable();
            unchecked
            {
                tw.Put32(0x00010000);                // Fixed    version 0x00010000 (1.0)
                tw.Put16((uint)YMax);                // FWord     ascent  Distance from baseline of highest ascender
                tw.Put16((uint)YMin);                // FWord     descent Distance from baseline of lowest descender
                tw.Put16(Inp.LineGap);               // FWord     lineGap typographic line gap
                tw.Put16((uint)advanceWidthMax);     // uFWord       advanceWidthMax must be consistent with horizontal metrics
                tw.Put16((uint)minLeftSideBearing);  // FWord     minLeftSideBearing      must be consistent with horizontal metrics
                tw.Put16((uint)minRightSideBearing); // FWord     minRightSideBearing     must be consistent with horizontal metrics
                tw.Put16((uint)xMaxExtent);          // FWord     xMaxExtent      max(lsb + (xMax-xMin))
                tw.Put16(1);                         // int16     caretSlopeRise  used to calculate the slope of the caret (rise/run) set to 1 for vertical caret
                tw.Put16(0);                         // int16     caretSlopeRun   0 for vertical
                tw.Put16(0);                         // FWord     caretOffset     set value to 0 for non-slanted fonts
                tw.Put16(0);                         // int16     reserved        set value to 0
                tw.Put16(0);                         // int16     reserved        set value to 0
                tw.Put16(0);                         // int16     reserved        set value to 0
                tw.Put16(0);                         // int16     reserved        set value to 0
                tw.Put16(0);                         // int16     metricDataFormat 0 for current format
                tw.Put16((uint)GList.Count);         // uint16    numOfLongHorMetrics number of advance widths in metrics table
            }
            tw.EndTable(TrueType.Tid.hhea);

            // 'loca' table ( glyph locations )
            tw.BeginTable();
            foreach (uint loc in locations)
            {
                tw.Put32(loc);
            }
            tw.EndTable(TrueType.Tid.loca);

            // 'maxp' maximum profile table
            tw.BeginTable();
            tw.Put32(0x00010000);                 // version
            tw.Put16((uint)GList.Count);          // numGlyphs the number of glyphs in the font
            tw.Put16((uint)maxPoints);            // maxPoints       points in non-compound glyph
            tw.Put16((uint)maxContours);          // maxContours     contours in non-compound glyph
            tw.Put16((uint)maxComponentPoints);   // maxComponentPoints      points in compound glyph ( todo )
            tw.Put16((uint)maxComponentContours); // maxComponentContours    contours in compound glyph ( todo )
            tw.Put16(2);                          // maxZones        set to 2
            tw.Put16(0);                          // maxTwilightPoints       points used in Twilight Zone (Z0)
            tw.Put16(0);                          // maxStorage      number of Storage Area locations
            tw.Put16(0);                          // maxFunctionDefs number of FDEFs
            tw.Put16(0);                          // maxInstructionDefs      number of IDEFs
            tw.Put16(0);                          // maxStackElements        maximum stack depth
            tw.Put16(0);                          // maxSizeOfInstructions   byte count for glyph instructions
            tw.Put16((uint)maxComponentElements); // maxComponentElements    number of glyphs referenced at top level
            tw.Put16((uint)maxComponentDepth);    // maxComponentDepth levels of recursion, set to 0 if font has only simple glyphs
            tw.EndTable(TrueType.Tid.maxp);

            // 'cmap' table : doesn't seem to be needed by PDF ( PDF has own ToUnicode representation ), may be useful when testing.
            // WriteCmap( tw );

            // 'name' naming

            /*
             * tw.BeginTable();
             * tw.Put16(0); // UInt16 format  Format selector. Set to 0.
             * tw.Put16(0); // UInt16 count   The number of nameRecords in this name table.
             * tw.Put16(0); // UInt16 stringOffset    Offset in bytes to the beginning of the name character strings.
             * // NameRecord  nameRecord[count]       The name records array.
             * // variable name character strings The character strings of the names. Note that these are not necessarily ASCII!
             * tw.EndTable( Tid.name );
             */

            // 'post' PostScript

            /*
             * tw.BeginTable();
             * tw.Put32(0x00030000); // Fixed      format  Format of this table
             * tw.Put32(0); // Fixed       italicAngle     Italic angle in degrees
             * tw.Put16(0); // FWord       underlinePosition       Underline position
             * tw.Put16(0); // FWord       underlineThickness      Underline thickness
             * tw.Put32(0); // uint32      isFixedPitch    Font is monospaced; set to 1 if the font is monospaced and 0 otherwise (N.B., to maintain compatibility with older versions of the TrueType spec, accept any non-zero value as meaning that the font is monospaced)
             * tw.Put32(0); // uint32      minMemType42    Minimum memory usage when a TrueType font is downloaded as a Type 42 font
             * tw.Put32(0); // uint32      maxMemType42    Maximum memory usage when a TrueType font is downloaded as a Type 42 font
             * tw.Put32(0); // uint32      minMemType1     Minimum memory usage when a TrueType font is downloaded as a Type 1 font
             * tw.Put32(0); // uint32      maxMemType1     Maximum memory usage when a TrueType font is downloaded as a Type 1 font
             * tw.EndTable( Tid.post );
             */

            tw.Finish();
            byte [] result = tw.ToArray();
            // Util.WriteFile( "test.ttf", result ); // ( for debugging )
            return(result);
        }
示例#27
0
        // ---  Attributes ---
        // -- Properties --
        // -- Public Attributes --
        // -- Private Attributes --
        // --- /Attributes ---

        // ---  Methods ---
        // -- Public Methods --

        /**
         * Loads all data from the TileMaps below the given node.
         * Returns a Graph object, loaded with all the required data.
         */
        public static Graph.Graph LoadGraph(Node root)
        {
            // Prepare the Graph instance.
            Graph.Graph graph = new Graph.Graph();

            // Find all tilemap subnodes.
            Generic.List <TileMap> tilemaps = FindTilemapsUnder(root);

            // Get the limits of all the tilesets.
            Rect2 limits = GetTilemapsLimits(tilemaps);
            // Compute the limits of the loops.
            Vector2 start = limits.Position;
            Vector2 end   = limits.Position + limits.Size;

            // Loop through each tilemap.
            foreach (TileMap tilemap in tilemaps)
            {
                // Loop through the limits of the tilemap.
                for (int x = (int)start.x; x < end.x; x++)
                {
                    for (int y = (int)start.y; y < end.y; y++)
                    {
                        // First, get the identifier of the cell.
                        int tileID = tilemap.GetCell(x, y);

                        // If the identifier is not -1.
                        if (tileID != -1)
                        {
                              {
                                // Get the name of the tile.
                                String tileName = tilemap.TileSet.TileGetName(tileID);

                                // Check if the tile is a wall.
                                ComputeWall(tileName, x, y, ref graph);

                                // Check if the tile is a vertex.
                                ComputeVertex(tileName, x, y, ref graph);

                                // Compute the cost of the tile.
                                ComputeCost(x, y, tilemap);
                            }
                        }

                        // If the tilemap handles zone splitting.
                        if (tilemap.CollisionMask == 0b1000)
                        {
                            // Compute the face this tile belongs to.
                            ComputeFace(x, y, ref graph);

                            // If there is a tile.
                            if (tileID != -1)
                            {
                                // Compute the resources on that tile.
                                ComputeResource(x, y, tilemap, ref graph);
                            }
                        }
                    }
                }
            }

            // Prepare the list of vertices to remove.
            Generic.List <Graph.Vertex> VerticesToRemove = new Generic.List <Graph.Vertex>();

            // Loop through each vertex.
            foreach (Graph.Vertex vtx in graph.Vertices)
            {
                // Check all four sides.
                Vector2[]  directions = new Vector2[] { Vector2.Up, Vector2.Down, Vector2.Left, Vector2.Right };
                foreach (Vector2 dir in directions)
                {
                    // Check if a wall is present and has not been computed.
                    Vector2   currentPosition = vtx.Position + dir;
                    Tile.Wall dirWall         = graph.GetWallAt(currentPosition);
                    if (dirWall != null && dirWall.Edge == null)
                    {
                        // Get the rooms on each side of the wall.
                        Graph.Face[] faces = graph.GetFacesFromWall(currentPosition);

                        // Start computing a new edge.
                        Graph.Edge edge = new Graph.Edge(faces);

                        // Add the edges to the face.
                        edge.RightFace = faces[0];
                        edge.LeftFace  = faces[1];

                        // Loop until a new vertex is found.
                        while (graph.GetVertexAt(currentPosition) == null)
                        {
                            // If the wall exists.
                            Tile.Wall wall = graph.GetWallAt(currentPosition);
                            if (wall != null)
                            {
                                // Add the wall to the edge.
                                edge.AddWall(wall);

                                // Increment the position.
                                currentPosition += dir;

                                // If the wall stops abruptly, stop execution.
                            }
                            else
                            {
                                throw new Exception("FATAL ERROR: Stray wall found @ " + currentPosition + " ...");
                            }
                        }

                        // Add the vertices to the edge.
                        edge.StartVertex = vtx;
                        edge.EndVertex   = graph.GetVertexAt(currentPosition);

                        // Add the edge to the graph.
                        vtx.Edges.Add(edge);
                        graph.AddEdge(edge);

                        // Add the edge to the face.
                        foreach (Graph.Face face in faces)
                        {
                            face.AddEdge(edge);
                        }
                    }
                }

                // After that is done, check if the vertex object is NOT a tower.
                if (!vtx.IsTower)
                {
                    // If the vertex has two edges.
                    if (vtx.Edges.Count == 2)
                    {
                        // Get the vertex's edges.
                        Tuple <Graph.Edge, Graph.Edge> edges = new Tuple <Graph.Edge, Graph.Edge>(
                            vtx.Edges[0], vtx.Edges[1]
                            );

                        // Merge the edges together.
                        edges.Item1.Merge(edges.Item2);

                        // Remove the second edge.
                        graph.RemoveEdge(edges.Item2);

                        // If the vertex has one single edge.
                    }
                    else if (vtx.Edges.Count == 1)
                    {
                        // Add the vertex's wall to the edge.
                        vtx.Edges[0].AddWall(vtx.Wall);
                    }


                    // Add the vertex to removal.
                    VerticesToRemove.Add(vtx);
                }
            }

            // Remove the vertices.
            foreach (Graph.Vertex vtx in VerticesToRemove)
            {
                graph.RemoveVertex(vtx);
            }

            // Return the generated graph.
            GD.Print(graph.ToString());
            return(graph);
        }
示例#28
0
        public void ReadGlyph(int gi, bool getPoints, out Glyph g)
        {
            GotoTable(Tid.loca);
            uint offset, next;

            if (IndexToLocFormat == 0)
            {
                Ix += (uint)gi * 2; offset = 2 * Get16(); next = 2 * Get16();
            }                                                                                 // Note the offsets are multiplied by 2 in the short format!
            else
            {
                Ix += (uint)gi * 4; offset = Get32(); next = Get32();
            }

            g = new Glyph();
            if (next == offset)
            {
                g.Contours = 0; g.Len = 0;
            }                                            // Empty glyph ( space )
            else
            {
                GotoTable(Tid.glyf);
                IxLimit = Ix + next;
                Ix     += offset;

                g.Pos      = (int)Ix;
                g.Contours = GetI16();
                g.XMin     = (short)GetI16();
                g.YMin     = (short)GetI16();
                g.XMax     = (short)GetI16();
                g.YMax     = (short)GetI16();

                if (g.Contours >= 0)                                     // Simple glyph
                {
                    ushort [] endPtsOfContours = new ushort[g.Contours]; // Shouldn't allocate this is !getPoints, but currently used to calculate # points.
                    uint      points           = 0;

                    if (getPoints)
                    {
                        for (int i = 0; i < g.Contours; i += 1)
                        {
                            uint ep = Get16();
                            endPtsOfContours[i] = (ushort)ep;
                        }
                        g.EndPoints = endPtsOfContours;
                        points      = (uint)g.EndPoints[g.Contours - 1] + 1;
                    }
                    else
                    {
                        Ix += (uint)(2 * (g.Contours - 1)); points = 1 + Get16();
                    }

                    g.Points = (ushort)points;
                    uint instructionLength = Get16();
                    g.InstructionLen = (int)instructionLength;

                    if (!getPoints) // Usually we don't need to parse the points.
                    {
                        Ix = IxLimit;
                    }
                    else
                    {
                        Ix += instructionLength;
                        byte [] flags = new byte[points];

                        byte flag = 0, rep = 0;
                        for (int i = 0; i < points; i += 1)
                        {
                            if (rep > 0)
                            {
                                rep -= 1;
                            }
                            else
                            {
                                flag = Get8(); if ((flag & 8) != 0)
                                {
                                    rep = Get8();
                                }
                            }
                            flags[i] = flag;
                        }
                        short [] xs = new short[points];
                        int      x  = 0;
                        for (int i = 0; i < points; i += 1)
                        {
                            flag = flags[i];
                            if ((flag & 2) != 0)
                            {
                                byte b = Get8(); if ((flag & 16) != 0)
                                {
                                    x += b;
                                }
                                else
                                {
                                    x -= b;
                                }
                            }
                            else if ((flag & 16) == 0)
                            {
                                x += GetI16();
                            }
                            xs[i] = (short)x;
                        }
                        short [] ys = new short[points];
                        int      y  = 0;
                        for (int i = 0; i < points; i += 1)
                        {
                            flag = flags[i];
                            if ((flag & 4) != 0)
                            {
                                byte b = Get8(); if ((flag & 32) != 0)
                                {
                                    y += b;
                                }
                                else
                                {
                                    y -= b;
                                }
                            }
                            else if ((flag & 32) == 0)
                            {
                                y += GetI16();
                            }
                            ys[i] = (short)y;
                        }
                        g.Flags = flags;
                        g.X     = xs;
                        g.Y     = ys;
                    }
                }
                else // Compound glyph
                {
                    Generic.List <Component> components = new Generic.List <Component>();
                    while (1 == 1)
                    {
                        uint flags = Get16();
                        uint glyphIndex = Get16();
                        uint a1, a2, s1 = 0, s2 = 0, s3 = 0, s4 = 0;
                        if ((flags & 1) != 0)
                        {
                            a1 = Get16(); a2 = Get16();
                        }
                        else
                        {
                            a1 = Get8(); a2 = Get8();
                        }
                        if ((flags & 8) != 0)
                        {
                            s1 = Get16();
                        }
                        else if ((flags & 0x40) != 0)
                        {
                            s1 = Get16(); s2 = Get16();
                        }
                        else if ((flags & 0x80) != 0)
                        {
                            s1 = Get16(); s2 = Get16(); s3 = Get16(); s4 = Get16();
                        }

                        Component nc; nc.GlyphIx = glyphIndex; nc.Flags = flags; nc.A1 = a1; nc.A2 = a2; nc.S1 = s1; nc.S2 = s2; nc.S3 = s3; nc.S4 = s4;
                        components.Add(nc);

                        if ((flags & 0x20) == 0)
                        {
                            break;
                        }
                    }
                    g.Components = components;
                }
                g.Len = (int)(Ix - g.Pos);
            }
        }
示例#29
0
 public abstract void Encode(string s, int start, int end, Generic.List <byte> buf);
示例#30
0
        /// <summary>
        /// Utility function to create DeploymentBaseOptions base on current vsMsDeployObject
        /// </summary>
        /// <param name="vSMSDeployObject"></param>
        /// <returns></returns>
        public static /*Deployment.DeploymentBaseOptions*/ dynamic CreateBaseOptions(VSMSDeployObject vSMSDeployObject)
        {
            // /*Deployment.DeploymentBaseOptions*/dynamic baseOptions = new Microsoft.Web.Deployment.DeploymentBaseOptions();
            /*Deployment.DeploymentBaseOptions*/
            dynamic baseOptions = MSWebDeploymentAssembly.DynamicAssembly.CreateObject("Microsoft.Web.Deployment.DeploymentBaseOptions");

            if (vSMSDeployObject.IsLocal)
            {
                // do nothing
            }
            else if (!vSMSDeployObject.UseSeparatedCredential)
            {
                baseOptions.ComputerName = vSMSDeployObject.ComputerName;
            }
            else
            {
                baseOptions.ComputerName = vSMSDeployObject.ComputerName;
                baseOptions.UserName     = vSMSDeployObject.UserName;
                baseOptions.Password     = vSMSDeployObject.Password;
            }

            baseOptions.PrefetchPayload = vSMSDeployObject.PrefetchPayload;
            baseOptions.IncludeAcls     = vSMSDeployObject.IncludeAcls;
            if (!string.IsNullOrEmpty(vSMSDeployObject.AuthenticationType))
            {
                baseOptions.AuthenticationType = vSMSDeployObject.AuthenticationType;
            }
            if (!string.IsNullOrEmpty(vSMSDeployObject.EncryptPassword))
            {
                baseOptions.EncryptPassword = vSMSDeployObject.EncryptPassword;
            }

            if (!string.IsNullOrEmpty(vSMSDeployObject.WebServerManifest))
            {
                baseOptions.WebServerConfiguration.WebServerManifest = System.IO.Path.GetFileName(vSMSDeployObject.WebServerManifest);
            }
            if (!string.IsNullOrEmpty(vSMSDeployObject.WebServerDirectory))
            {
                baseOptions.WebServerConfiguration.WebServerDirectory = vSMSDeployObject.WebServerDirectory;
            }

            if (!string.IsNullOrEmpty(vSMSDeployObject.WebServerAppHostConfigDirectory))
            {
                baseOptions.WebServerConfiguration.ConfigurationDirectory = vSMSDeployObject.WebServerAppHostConfigDirectory;
            }


            if (vSMSDeployObject.RetryInterval >= 0)
            {
                baseOptions.RetryInterval = vSMSDeployObject.RetryInterval;
            }
            if (vSMSDeployObject.RetryAttempts >= 0)
            {
                baseOptions.RetryAttempts = vSMSDeployObject.RetryAttempts;
            }

            if (!string.IsNullOrEmpty(vSMSDeployObject.UserAgent))
            {
                baseOptions.UserAgent = vSMSDeployObject.UserAgent;
            }

            //remove duplicate items appearing in both "EnableLinks" and "DisableLinks" caused by the default value set by publish target file
            Generic.List <string> enabledLinkList  = ConvertStringIntoList(vSMSDeployObject.EnableLinks);
            Generic.List <string> disabledLinkList = ConvertStringIntoList(vSMSDeployObject.DisableLinks);
            foreach (string link in disabledLinkList)
            {
                if (LinkContainedInTheCollection(link, enabledLinkList))
                {
                    enabledLinkList.Remove(link);
                }
            }

            ChangeLinkExtensionEnableStatue(baseOptions, disabledLinkList, false);
            ChangeLinkExtensionEnableStatue(baseOptions, enabledLinkList, true);

            return(baseOptions);
        }
示例#31
0
            internal static PythonList Convert(ComprehensionIterator[] iters) {
                Generic.List<ComprehensionFor> cfCollector =
                    new Generic.List<ComprehensionFor>();
                Generic.List<Generic.List<ComprehensionIf>> cifCollector =
                    new Generic.List<Generic.List<ComprehensionIf>>();
                Generic.List<ComprehensionIf> cif = null;
                for (int i = 0; i < iters.Length; i++) {
                    if (iters[i] is ComprehensionFor) {
                        ComprehensionFor cf = (ComprehensionFor)iters[i];
                        cfCollector.Add(cf);
                        cif = new Generic.List<ComprehensionIf>();
                        cifCollector.Add(cif);
                    } else {
                        ComprehensionIf ci = (ComprehensionIf)iters[i];
                        cif.Add(ci);
                    }
                }

                PythonList comps = new PythonList();
                for (int i = 0; i < cfCollector.Count; i++)
                    comps.Add(new comprehension(cfCollector[i], cifCollector[i].ToArray()));
                return comps;
            }
示例#32
0
 internal static ComprehensionIterator[] RevertComprehensions(PythonList comprehensions) {
     Generic.List<ComprehensionIterator> comprehensionIterators =
         new Generic.List<ComprehensionIterator>();
     foreach (comprehension comp in comprehensions) {
         ComprehensionFor cf = new ComprehensionFor(expr.Revert(comp.target), expr.Revert(comp.iter));
         comprehensionIterators.Add(cf);
         foreach (expr ifs in comp.ifs) {
             comprehensionIterators.Add(new ComprehensionIf(expr.Revert(ifs)));
         }
     }
     return comprehensionIterators.ToArray();
 }