public AvatarFileEngine(string uri) { // uri begins with "avatar:/" m_AvatarHash = uri.Substring(8); QPixmap pixmap = (QPixmap) Synapse.Xmpp.AvatarManager.GetAvatar(m_AvatarHash); // FIXME: This doesn't seem very efficient... QBuffer buffer = new QBuffer(); buffer.Open((uint)QIODevice.OpenModeFlag.WriteOnly); pixmap.Save(buffer, "PNG"); buffer.Close(); m_Buffer = new byte[buffer.Size()]; Marshal.Copy(buffer.Data().Data().ToIntPtr(), m_Buffer, 0, m_Buffer.Length); }
public string ToHtml() { var builder = new StringBuilder(); var document = base.Document(); bool isFirstBlock = true; var block = document.Begin(); while (block.IsValid()) { if (!isFirstBlock) builder.Append("<br/>"); isFirstBlock = false; QTextBlock.iterator it; //for (it = block.Begin(); !it.AtEnd(); it = it++) { for (it = block.Begin(); !it.AtEnd(); it = it.Next()) { var fragment = it.Fragment(); var format = fragment.CharFormat(); if (format.IsImageFormat()) { var imageFormat = format.ToImageFormat(); var name = imageFormat.Name(); var data = document.Resource((int)QTextDocument.ResourceType.ImageResource, new QUrl(name)); if (data.type() == QVariant.TypeOf.Pixmap) { var pixmap = (QPixmap)data; var tempArray = new QByteArray(); var tempBuffer = new QBuffer(tempArray); pixmap.Save(tempBuffer, "PNG"); string imageString = tempArray.ToBase64().ConstData(); builder.AppendFormat("<img alt=\"[embeded image]\" src=\"data:image/png;base64,{0}\" />", imageString); } } else { var link = format.AnchorHref(); var bold = (format.FontWeight() == (int)QFont.Weight.Bold); var underline = format.FontUnderline() && String.IsNullOrEmpty(link); var italic = format.FontItalic(); var strike = format.FontStrikeOut(); if (!String.IsNullOrEmpty(link)) { link = Util.EscapeHtml(link); builder.AppendFormat("<a href=\"{0}\" title=\"{0}\">", link); } if (bold) builder.Append("<b>"); if (underline) builder.Append("<u>"); if (italic) builder.Append("<i>"); if (strike) builder.Append("<s>"); var text = fragment.Text(); text = Util.EscapeHtml(text); text = text.Replace(" ", " "); text = text.Replace("\t", "    "); text = text.Replace("\r\n", "<br/>"); text = text.Replace("\r", "<br/>"); text = text.Replace("\n", "<br/>"); text = text.Replace("\u2028", "<br/>"); builder.Append(text); if (strike) builder.Append("</s>"); if (italic) builder.Append("</i>"); if (underline) builder.Append("</u>"); if (bold) builder.Append("</b>"); if (!String.IsNullOrEmpty(link)) builder.Append("</a>"); } } block = block.Next(); } return builder.ToString(); }