/// <summary> /// Parse links contained in the header of an IRestResponse object. /// </summary> /// <param name="response"></param> public PageLinks(IRestResponse response) { if (response == null) { return; } if (response.Headers.Any(h => h.Name == Constants.HEADER_LINK)) { string linkHeader = response.Headers.FirstOrDefault(t => t.Name == Constants.HEADER_LINK).Value.ToString(); List <string> links = linkHeader.Split(DELIM_LINKS).ToList(); foreach (string link in links) { List <string> segments = link.Split(DELIM_LINK_PARAM).ToList(); if (segments.Count < 2) { continue; } LinkPart = segments.First().Trim(); if (!LinkPart.StartsWith("<") || !LinkPart.EndsWith(">")) //$NON-NLS-1$ //$NON-NLS-2$ { continue; } LinkPart = LinkPart.TrimStart('<').TrimEnd('>'); foreach (string segment in segments) { List <string> rel = segment.Trim().Split('=').ToList(); if (rel.Count < 2 || !Constants.META_REL.Equals(rel.First())) { continue; } RelValue = rel.ElementAt(1); if (RelValue.StartsWith(@"""") && RelValue.EndsWith(@"""")) //$NON-NLS-1$ //$NON-NLS-2$ { RelValue = RelValue.TrimStart('"').TrimEnd('"'); } if (Constants.META_FIRST.Equals(RelValue)) { first = LinkPart; } else if (Constants.META_LAST.Equals(RelValue)) { last = LinkPart; } else if (Constants.META_NEXT.Equals(RelValue)) { next = LinkPart; } else if (Constants.META_PREV.Equals(RelValue)) { prev = LinkPart; } } } } else { next = response.Headers.FirstOrDefault(t => t.Name == Constants.HEADER_NEXT) == null ? "" : response.Headers.FirstOrDefault(t => t.Name == Constants.HEADER_NEXT).Value.ToString(); last = response.Headers.FirstOrDefault(t => t.Name == Constants.HEADER_LAST) == null ? "" : response.Headers.FirstOrDefault(t => t.Name == Constants.HEADER_LAST).Value.ToString(); } }
protected void Rebuild() { m_Updating = true; DeleteAllChildren(); Size size = Size.Zero; if (m_Document != null && m_Document.Paragraphs.Count > 0) { #if USE_KNUTH_PLASS_LINE_BREAKING LineBreaker lineBreaker = new RichText.KnuthPlass.LineBreaker(Skin.Renderer, Skin.DefaultFont); #else LineBreaker lineBreaker = new RichText.Simple.LineBreaker(Skin.Renderer, Skin.DefaultFont); #endif int y = 0; int x; int width; int height; foreach (Paragraph paragraph in m_Document.Paragraphs) { if (paragraph is ImageParagraph) { ImageParagraph imageParagraph = paragraph as ImageParagraph; ImagePanel image = new ImagePanel(this); image.ImageName = imageParagraph.ImageName; if (imageParagraph.ImageSize != null) { image.Size = (Size)imageParagraph.ImageSize; } if (imageParagraph.TextureRect != null) { image.TextureRect = (Rectangle)imageParagraph.TextureRect; } if (imageParagraph.ImageColor != null) { image.ImageColor = (Color)imageParagraph.ImageColor; } image.DoMeasure(Size.Infinity); image.DoArrange(paragraph.Margin.Left, y + paragraph.Margin.Top, image.MeasuredSize.Width, image.MeasuredSize.Height); size.Width = Math.Max(size.Width, image.MeasuredSize.Width + paragraph.Margin.Left + paragraph.Margin.Right); y += image.MeasuredSize.Height + paragraph.Margin.Top + paragraph.Margin.Bottom; } else { List <TextBlock> textBlocks = lineBreaker.LineBreak(paragraph, m_BuildWidth); if (textBlocks != null) { x = paragraph.Margin.Left; y += paragraph.Margin.Top; width = 0; height = 0; foreach (TextBlock textBlock in textBlocks) { if (textBlock.Part is LinkPart) { LinkPart linkPart = textBlock.Part as LinkPart; LinkLabel link = new LinkLabel(this); link.Text = textBlock.Text; link.Link = linkPart.Link; link.Font = linkPart.Font; link.LinkClicked += OnLinkClicked; if (linkPart.Color != null) { link.TextColor = (Color)linkPart.Color; } if (linkPart.HoverColor != null) { link.HoverColor = (Color)linkPart.HoverColor; } if (linkPart.HoverFont != null) { link.HoverFont = linkPart.HoverFont; } link.DoMeasure(Size.Infinity); link.DoArrange(new Rectangle(x + textBlock.Position.X, y + textBlock.Position.Y, textBlock.Size.Width, textBlock.Size.Height)); width = Math.Max(width, link.ActualRight); height = Math.Max(height, link.ActualBottom); } else if (textBlock.Part is TextPart) { TextPart textPart = textBlock.Part as TextPart; Text text = new Text(this); text.String = textBlock.Text; text.Font = textPart.Font; if (textPart.Color != null) { text.TextColor = (Color)textPart.Color; } text.DoMeasure(Size.Infinity); text.DoArrange(new Rectangle(x + textBlock.Position.X, y + textBlock.Position.Y, textBlock.Size.Width, textBlock.Size.Height)); width = Math.Max(width, text.ActualRight + 1); height = Math.Max(height, text.ActualBottom + 1); } } size.Width = Math.Max(size.Width, width + paragraph.Margin.Right); y = height + paragraph.Margin.Bottom; } } } size.Height = y; } m_TextSize = size; m_NeedsRebuild = false; m_Updating = false; }