// Use this for initialization
    void Start()
    {
        _r = new HLRemoting.MyTextRenderer(FontName, FontSize);
        var il = _r.GetGryphs(Content);
        System.Collections.Generic.List<Sprite> sl = new System.Collections.Generic.List<Sprite>();
        float x = StartPosition;
        var mt = GetComponent<RectTransform>() as RectTransform;
        float pw = 0.0f;
        float height = il.Max((ii) => ii.Height)/100;
        float top = 0.0f;
        for(int i=0;i<il.Length;i++){
            var image=il[i];
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            image.Save(string.Format("D:\\unity\\akane_{0}.png",i), System.Drawing.Imaging.ImageFormat.Png);
            Texture2D t = new Texture2D(image.Width, image.Height);
            t.LoadImage(ms.GetBuffer());
            Sprite s = Sprite.Create(t, new Rect(0, 0, image.Width, image.Height), new Vector2(0.5f, 0.5f));
            sl.Add(s);

            GameObject go = new GameObject();
            var sr = go.AddComponent<SpriteRenderer>() as SpriteRenderer;
            sr.sprite = s;
            var tr = go.GetComponent<Transform>() as Transform;
            tr.parent = mt;
            tr.localScale = new Vector3(FontScale, FontScale, FontScale);
            x += (pw + s.bounds.size.x) / 2.0f* FontScale;
            tr.position = new Vector3(x, tr.position.y + top, tr.position.z);
            pw = s.bounds.size.x ;
            if (StartPosition + PaperWidh <= x + s.bounds.size.x / 2.0f)
            {
                pw = 0.0f;
                x = StartPosition;
                top -= height / 2.0f;
            }
            //x += image.Width * 0.01f;
            Debug.Log(x);
        }
    }
    // Use this for initialization
    void Start()
    {
        _tr = new HLRemoting.MyTextRenderer("メイリオ", FontSize);

        GameObject prefab = (GameObject)Resources.Load("Prefabs/MailItemButton");

        XmlDocument xd = new XmlDocument();
        using(System.IO.FileStream s = new System.IO.FileStream("happylagoon.xml",System.IO.FileMode.Open))
        {
            xd.Load(s);
        }
        int key = 1;
        foreach (XmlNode n in xd.DocumentElement.ChildNodes)
        {
            var o = Instantiate(prefab);
            var rt = o.GetComponent<RectTransform>();
            o.transform.SetParent(MailList.transform, false);
            var c = o.GetComponent<MailItemButtonController>();
            c.Key = key;
            foreach (XmlAttribute a in n.Attributes)
            {
                if (a.Name == "Author") c.Name = a.Value;
                if (a.Name == "Subject") c.Subject = a.Value;
                if (a.Name == "Icon") c.Icon = LoadSprite(a.Value);
                if (a.Name.Equals("Stamp")) c.Stamp = LoadSprite(a.Value);
                if (a.Name.Equals("Adventure")) c.AdventurePart = a.Value;
            }
            foreach (XmlNode child in n.ChildNodes)
            {
                if (child.Name.Equals("Content"))
                {
                    c.Content = child.InnerText;
                }
                else if (child.Name.Equals("Replies"))
                {
                    c.ReplyTitles = new System.Collections.Generic.List<string>();
                    c.Replies = new System.Collections.Generic.List<string>();
                    foreach (XmlNode rc in child.ChildNodes)
                    {
                        if (rc.Name.Equals("Reply"))
                        {
                            foreach (XmlAttribute ra in rc.Attributes)
                            {
                                if (ra.Name.Equals("Subject"))
                                {
                                    c.ReplyTitles.Add(ra.Value);
                                    break;
                                }
                            }
                            c.Replies.Add(rc.InnerText);
                            if (c.ReplyTitles.Count < c.Replies.Count) c.ReplyTitles.Add("Subjectが設定されていません");
                        }
                    }
                }
            }
            key += 1;
        }

        _emoji = new System.Collections.Generic.Dictionary<string, System.Drawing.Image>();
        _emoji.Add("hare", LoadImage("emoji/hare"));
        _emoji.Add("ame", LoadImage("emoji/ame"));
        _emoji.Add("kumori", LoadImage("emoji/kumori"));

        //for (int i = 0; i < 15; i++)
        //{
        //    var o = Instantiate(prefab);
        //    o.transform.parent = MailList.transform;
        //    var c = o.GetComponent<MailItemButtonController>();
        //    c.Name = string.Format("{0}item", i);
        //    c.Subject = string.Format("{0}subject", i);
        //}
    }