public Bitmap RenderAA(double maxHeight, double maxWidth) { //GraphicsPathは空行が考慮されない NCSize size = Cmt.Size; double scale = 1.0; if (maxHeight > 0 && size.Height > maxHeight) { scale = maxHeight / (double)size.Height; size.Width = scale * (double)size.Width; size.Height = maxHeight; } if (maxWidth > 0 && size.Width > maxWidth) { double scaleX = maxWidth / (double)size.Width; size.Height = scaleX * (double)size.Height; size.Width = maxWidth; scale *= scaleX; } RectangleF rect = new RectangleF(0, 0, (float)size.Width, (float)size.Height); using (var bitmap = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { using (Graphics gr = Graphics.FromImage(bitmap)) { gr.SmoothingMode = SmoothingMode.HighQuality; gr.CompositingQuality = CompositingQuality.HighQuality; gr.ScaleTransform((float)scale, (float)scale); System.Drawing.Brush fillBrush = new System.Drawing.SolidBrush(Color); gr.DrawString(Cmt.Text, Font, fillBrush, 0, 0); } return(new Bitmap(bitmap)); } }
public Bitmap RenderImage(Filter filter) { if (Cmt.IsAA) { return(RenderAA(filter.CanvasHeight, 0)); } if (Cmt.IsPerm) { return(RenderAA(filter.RowHeight, filter.CanvasWidth)); } List <Bitmap> ary = BitmapArray(); Bitmap result = ConcatBitmap(ary); if (result != null) { NCSize realSize = new NCSize(result.Width, result.Height); Cmt.Size = realSize; } return(result); }
public FrameData GetFrameData(ICanvas canvas) { var time = canvas.CurrentSecond; List <CommentLayout> layouts = new List <CommentLayout>(); FrameData result = new FrameData() { Layouts = layouts, Perm = null, Vote = null, }; var RangesTop = new List <Range>(); var RangesBottom = new List <Range>(); double commentDuration = this.CommentDuration; var operatedComments = new List <Comment>(); foreach (var perm in Perms) { if (time >= perm.StartTime && time < perm.EndTime) { if (perm.Comment.Size.Width <= 0) { perm.Comment.Size = canvas.MeasureText(perm.Comment); } result.Perm = perm; break; } if (time > perm.EndTime) { break; } } foreach (var vote in Votes) { } foreach (var comment in Comments) { //var vpos = GetActualVpos(comment.Content.Vpos, video.Duration, commentDuration); var vpos = comment.Vpos; if (time - commentDuration >= vpos / 100.0 || vpos / 100.0 >= time) { if (vpos / 100.0 >= time + 10.0) { break; } continue; } //var mails = comment.Mail.Split(' '); if (comment.ContainsCommand("invisible")) { continue; } if (comment.FontSize > 0) { } else if (comment.ContainsCommand("small")) { comment.FontSize = FontSizeSmall; } else if (comment.ContainsCommand("big")) { comment.FontSize = FontSizeBig; } else { comment.FontSize = FontSizeDefault; } var fontSizeActual = comment.FontSize; //if (ContainsCommand(mails, "mincho")) canvas.FontKind = FontKind.Mincho; //else if (ContainsCommand(mails, "gothic")) canvas.FontKind = FontKind.Gothic; //else canvas.FontKind = FontKind.Default; var r = new Coordinate(); var commentSize = new NCSize(); if (comment.Size.Width > 0) { commentSize = comment.Size; } else { commentSize = canvas.MeasureText(comment); comment.Size = commentSize; } //if (ContainsCommand(mails, "ue") || ContainsCommand(mails, "shita")) //{ // if (commentSize.Width > canvas.CanvasWidth + 1) // { // comment.FontSize *= canvas.CanvasWidth / commentSize.Width; // //comment.FontSize.Relative = Math.Max(comment.FontSize, GetRelativeSize(1, canvas)); // canvas.FontSize = comment.FontSize; // fontSizeActual = comment.FontSize; // commentSize = canvas.MeasureText(comment); // comment.Size = commentSize; // } //} bool overFlow = false; //if (ContainsCommand(mails, "ue")) //{ // r = new Coordinate(canvas.CanvasWidth / 2.0 - commentSize.Width / 2.0, Math.Max(0, comment.LastY)); // var changed = false; // while(! CheckRanges(RangesTop,new Range(r.Y, r.Y + fontSizeActual))) // { // r.Y += fontSizeActual; // changed = true; // } // if (changed) // { // foreach(var range in RangesTop) // { // if(range.B<r.Y && CheckRanges(RangesTop,new Range(range.B, range.B+fontSizeActual))) // r.Y = range.B; // } // } // canvas.Baseline = Baseline.Top; // comment.LastY = r.Y; // RangesTop.Add(new Range(r.Y, r.Y + fontSizeActual)); // overFlow = FixOverflow(ref r.Y, canvas.CanvasHeight,canvas); //} //else if (ContainsCommand(mails, "shita")) //{ // r = new Coordinate(canvas.CanvasWidth / 2.0 - commentSize.Width / 2.0, Math.Max(0, comment.LastY)); // var changed = false; // while (!CheckRanges(RangesBottom, new Range(r.Y, r.Y + fontSizeActual))) // { // r.Y += fontSizeActual; // changed = true; // } // if (changed) // { // foreach (var range in RangesBottom) // { // if (range.B < r.Y && CheckRanges(RangesBottom, new Range(range.B, range.B+fontSizeActual))) // r.Y = range.B; // } // } // canvas.Baseline = Baseline.Bottom; // comment.LastY = r.Y; // RangesBottom.Add(new Range(r.Y, r.Y + fontSizeActual)); // overFlow = FixOverflow(ref r.Y, canvas.CanvasHeight,canvas); // r.Y = canvas.CanvasHeight - r.Y; //} //else { r = GetFromOperated(operatedComments, comment, canvas.Duration, commentDuration, time, canvas, FontSizeDefault); comment.LastY = r.Y; canvas.Baseline = Baseline.Middle; overFlow = FixOverflow(ref r.Y, canvas.CanvasHeight, canvas); r.Y += FontSizeDefault / 8.0; operatedComments.Add(comment); } if (result.Perm != null) { r.Y += canvas.RowHeight; } layouts.Add( new CommentLayout() { Comment = comment, Coordinate = r, OverFlow = overFlow } ); //canvas.FillText(comment, r, overFlow); } //canvas.Done(); return(result); }