Ejemplo n.º 1
0
 public static byte[] CalcKey(byte[] head, byte[] key, SplitWord splitWord = SplitWord.TableItem)
 {
     if (head.Length > 255)
     {
         throw new Exception("not support key >255 bytes");
     }
     byte[] finalkey = new byte[1 + head.Length + 1 + (key != null ? key.Length : 0)];
     //key的构成 keylen + key + splitword + value
     //splitword 00 controlitem
     //splitword 01 valueitem
     //splitword >0 otherinfo
     finalkey[0] = (byte)head.Length;
     for (var i = 0; i < head.Length; i++)
     {
         finalkey[i + 1] = head[i];
     }
     ;
     finalkey[1 + head.Length] = (byte)splitWord;
     if (key != null)
     {
         for (var i = 0; i < key.Length; i++)
         {
             finalkey[1 + head.Length + 1 + i] = key[i];
         }
     }
     return(finalkey);
 }
Ejemplo n.º 2
0
    public void Start()
    {
        //分词测试
        bool canSplit1 = new SplitWord("catgood", new List <string> {
            "good", "cat"
        }).canSplit();
        bool canSplit2 = new SplitWord("castlejoycastlecatjoy", new List <string> {
            "castle", "cat", "joy"
        }).canSplit();
        bool canSplit3 = new SplitWord("castlejoycastlecatjoya", new List <string> {
            "castle", "cat", "joy"
        }).canSplit();
        bool canSplit4 = new SplitWord("gogoodgogood", new List <string> {
            "good", "go"
        }).canSplit();


        //重叠矩形测试
        OverlapRect overlapRect  = new OverlapRect(2, 2, 5);
        int         overlapCount = overlapRect.OverlapCount();

        Debug.Log("oc:" + overlapCount);

        //绘制随机矩形,方便调试
        GameObject image = Resources.Load <GameObject>("Image");
        string     a     = "";

        for (int i = 0; i < overlapRect.rectCenters.Length; i++)
        {
            Position   position = overlapRect.rectCenters[i];
            GameObject go       = Instantiate(image);
            go.transform.SetParent(uiContainer);
            go.transform.position = new Vector3(position.x, position.y);
            go.name = (i + 1).ToString();
            a      += string.Format("({0},{1}),", position.x, position.y);
        }
        Debug.Log(a);
    }
Ejemplo n.º 3
0
		// Draw each line
		public void Draw(Brush brush)
				{
					graphics.SelectBrush(brush);
					if (linePositions.Length == 0)
						return;
					int currentLine = 0;
					int textStart = 0;
					int textLength = 0;
						
					SplitWord word = new SplitWord(0,0);
					for (int i = 0; i <= wordCount; i++)
					{
						if (i != wordCount)
						{
							word = words[i];
							if(word.line== -1)
								continue;
							if (word.line == currentLine)
							{
								textLength += word.length;
								continue;
							}
						}
						Point linePosition = linePositions[currentLine];
						// Draw if some of it is within layout.
						if(linePosition.X <= layout.Right && linePosition.Y <= layout.Bottom)
						{
							if (HotKeyIdx >= textStart && HotKeyIdx < textStart+textLength)
							{
								String startString = text.Substring(textStart, 
													 	HotKeyIdx -  textStart );
								String endString = text.Substring(HotKeyIdx+1, 
														textLength - (HotKeyIdx -textStart) -1);
								graphics.ToolkitGraphics.DrawString(startString, linePosition.X, linePosition.Y, null);  
								Font underlineFont = new Font (font, font.Style | FontStyle.Underline);
								float startWidth = graphics.MeasureString(startString,font).Width;
								float hotkeyWidth = graphics.MeasureString(text.Substring(HotKeyIdx,1),underlineFont).Width;
								graphics.SelectFont(font);
								graphics.ToolkitGraphics.DrawString(endString,
											linePosition.X+(int)(startWidth+hotkeyWidth), linePosition.Y, null);
								graphics.SelectFont(underlineFont);
								graphics.ToolkitGraphics.DrawString(text.Substring(HotKeyIdx,1),
											linePosition.X+(int)startWidth, linePosition.Y, null);
								graphics.SelectFont(font);
							} 
							else
							{
								String lineText = text.Substring(textStart, textLength);
								graphics.ToolkitGraphics.DrawString(lineText, linePosition.X, linePosition.Y, null);
							}
						}
						textStart = word.start;
						textLength = word.length;
						currentLine = word.line;
					}
				}
Ejemplo n.º 4
0
		public void LayoutByWords()
				{
					// Break the string into "words". Each word has a start pos, end pos and measured size.
					// Each new line group is treated as a "word" as is each whitespace.
					wordCount = 0;
					words = new SplitWord[16];
					int start = 0;
					int len = text.Length;
					for(int i = 0; i < len;)
					{
						start = i;
						char c = text[i];
						// Look for \r on its own, \n on its own or \r\n.
						if(c == '\r')
						{
							if(i < (len - 1) && text[i+1]=='\n')
							{
								i += 2;
							}
							else
							{
								i++;
							}
						}
						else if(c == '\n')
						{
							i++;
						}
						else
						{
							// Skip over the whitespace.
							while(i < len && Char.IsWhiteSpace(text[i]))
							{
								i++;
							}
							// We are at the start of text so skip over the text.
							if(i == start)
							{
								while(i < len)
								{
									c = text[i];
									if(Char.IsWhiteSpace(c) ||
									   c == '\n' || c == '\r')
									{
										break;
									}
									i++;
								}
							}
						}
						// Dynamically allocate the array if we need more space.
						if(wordCount >= words.Length)
						{
							SplitWord[] newWords = new SplitWord[words.Length * 2];
							Array.Copy(words, newWords, words.Length);
							words = newWords;
						}
						// Add the word.
						words[wordCount++] = new SplitWord(start, i - start);
					}
					Layout();
				}