Skip to content

Commit

Permalink
Switch all text rendering to draw text safe
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Apr 29, 2020
1 parent 5b351a6 commit 5547a62
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/AudioAnalysisTools/StandardSpectrograms/ImageTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public Image<Rgb24> DrawTrackTitle(Image<Rgb24> bmp, string title)
{
bmp.Mutate(g =>
{
g.DrawText(title, Drawing.Tahoma8, Color.Black, new PointF(10, bmp.Height - 2));
g.DrawTextSafe(title, Drawing.Tahoma8, Color.Black, new PointF(10, bmp.Height - 2));
});
return bmp;
}
Expand Down Expand Up @@ -299,9 +299,9 @@ public Image<Rgb24> DrawNamedScoreArrayTrack(Image<Rgb24> bmp)
bmp.Mutate(g =>
{
var font = Drawing.Arial10;
g.DrawText(this.Name, font, Color.Red, new PointF(10, this.topOffset));
g.DrawText(this.Name, font, Color.Red, new PointF(length / 2, this.topOffset));
g.DrawText(this.Name, font, Color.Red, new PointF(length - 80, this.topOffset));
g.DrawTextSafe(this.Name, font, Color.Red, new PointF(10, this.topOffset));
g.DrawTextSafe(this.Name, font, Color.Red, new PointF(length / 2, this.topOffset));
g.DrawTextSafe(this.Name, font, Color.Red, new PointF(length - 80, this.topOffset));
});

return bmp;
Expand Down Expand Up @@ -978,7 +978,7 @@ public static void DrawScoreTrack(Image<Rgb24> bmp, double[] array, int yOffset,

bmp.Mutate(g =>
{
g.DrawText(title, Drawing.Arial10, Color.White, new PointF(imageWidth + 5, yOffset));
g.DrawTextSafe(title, Drawing.Arial10, Color.White, new PointF(imageWidth + 5, yOffset));
});
}

Expand Down Expand Up @@ -1021,7 +1021,7 @@ public static Image<Rgb24> DrawGrayScaleScoreTrack(double[] array, double minVal

bmp.Mutate(g =>
{
g.DrawText(title, Drawing.Tahoma8, Color.White, new PointF(imageWidth + 5, 0));
g.DrawTextSafe(title, Drawing.Tahoma8, Color.White, new PointF(imageWidth + 5, 0));
});

return bmp;
Expand Down Expand Up @@ -1068,7 +1068,7 @@ public static Image<Rgb24> DrawBarScoreTrack(double[] order, double[] array, int
bmp.Mutate(g =>
{
g.FillRectangle(new SolidBrush(Color.Black), array.Length + 1, 0, endWidth, trackHeight);
g.DrawText(title, font, Color.White, new PointF(array.Length + 5, 2));
g.DrawTextSafe(title, font, Color.White, new PointF(array.Length + 5, 2));
});
return bmp;
}
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public static Image<Rgb24> DrawColourScoreTrack(double[] order, double[] array,
bmp.Mutate(g =>
{
g.FillRectangle(Brushes.Solid(Color.Black), array.Length + 1, 0, endWidth, trackHeight);
g.DrawText(title, font, Color.White, new PointF(array.Length + 5, 2));
g.DrawTextSafe(title, font, Color.White, new PointF(array.Length + 5, 2));
});

return bmp;
Expand Down Expand Up @@ -1134,7 +1134,7 @@ public static Image<Rgb24> DrawTitleTrack(int trackWidth, int trackHeight, strin
g.Clear(Color.Black);
Pen pen = new Pen(Color.White, 1);
g.DrawLine(new Pen(Color.Gray, 1), 0, 0, trackWidth, 0); //draw upper boundary
g.DrawText(title, Drawing.Tahoma9, Color.Wheat, new PointF(4, 3));
g.DrawTextSafe(title, Drawing.Tahoma9, Color.Wheat, new PointF(4, 3));
});
return bmp;
}
Expand Down Expand Up @@ -1289,14 +1289,14 @@ public static Image<Rgb24> DrawTimeTrack(TimeSpan fullDuration, TimeSpan startOf
hour = 0;
}

g.DrawText(hour.ToString(), stringFont, Color.White, new PointF(x + 2, 1)); //draw time
g.DrawTextSafe(hour.ToString(), stringFont, Color.White, new PointF(x + 2, 1)); //draw time
} //end over all pixels

g.DrawLine(whitePen, 0, 0, trackWidth, 0); //draw upper boundary
g.DrawLine(whitePen, 0, trackHeight - 1, trackWidth, trackHeight - 1); //draw lower boundary
g.DrawLine(whitePen, trackWidth, 0, trackWidth, trackHeight - 1); //draw right end boundary

g.DrawText(title, stringFont, Color.White, new PointF(trackWidth - 30, 2));
g.DrawTextSafe(title, stringFont, Color.White, new PointF(trackWidth - 30, 2));
});

return bmp;
Expand Down Expand Up @@ -1326,11 +1326,11 @@ public static Image<Rgb24> DrawTimeRelativeTrack(TimeSpan fullDuration, int trac
string time = "HHmm";
if (xAxisPixelDurationInMilliseconds < 60000)
{
g.DrawText(time, stringFont, Color.White, new PointF(0, 3)); //draw time
g.DrawTextSafe(time, stringFont, Color.White, new PointF(0, 3)); //draw time
}
else
{
g.DrawText("Hours", stringFont, Color.White, new PointF(0, 3)); //draw time
g.DrawTextSafe("Hours", stringFont, Color.White, new PointF(0, 3)); //draw time
}

// for columns, draw in X-axis lines
Expand Down Expand Up @@ -1364,7 +1364,7 @@ public static Image<Rgb24> DrawTimeRelativeTrack(TimeSpan fullDuration, int trac
time = $"{elapsedTimeSpan.TotalHours:f0}";
}

g.DrawText(time, stringFont, Color.White, new PointF(tickPosition, 2)); //draw time
g.DrawTextSafe(time, stringFont, Color.White, new PointF(tickPosition, 2)); //draw time
}
}

Expand Down Expand Up @@ -1432,15 +1432,15 @@ public static Image<Rgb24> DrawYearScaleVertical(int offset, int trackHeight)
// hour = 0;
//}
g.DrawLine(whitePen, 0, Y, trackWidth, Y);
g.DrawText(months[i], stringFont, Color.White, new PointF(1, Y + 6)); //draw time
g.DrawTextSafe(months[i], stringFont, Color.White, new PointF(1, Y + 6)); //draw time
} // end over all pixels

g.DrawLine(whitePen, 0, daysInYear + offset, trackWidth, daysInYear + offset);

//g.DrawLine(whitePen, 0, offset, trackWidth, offset); //draw lower boundary
// g.DrawLine(whitePen, duration, 0, duration, trackHeight - 1);//draw right end boundary

// g.DrawText(title, stringFont, Color.White, new PointF(duration + 4, 3));
// g.DrawTextSafe(title, stringFont, Color.White, new PointF(duration + 4, 3));
});

return bmp;
Expand Down Expand Up @@ -1473,15 +1473,15 @@ public static Image<Rgb24> DrawYearScale_horizontal(int trackWidth, int trackHei
g.DrawLine(whitePen, X, 0, X, trackHeight);

//g.DrawLine(whitePen, X, 0, X, trackWidth, Y);
g.DrawText(months[i], stringFont, Color.White, new PointF(X + 2, 2)); //draw time
g.DrawTextSafe(months[i], stringFont, Color.White, new PointF(X + 2, 2)); //draw time
} // end over all pixels

g.DrawLine(whitePen, 0, daysInYear, trackWidth, daysInYear);

//g.DrawLine(whitePen, 0, offset, trackWidth, offset); //draw lower boundary
// g.DrawLine(whitePen, duration, 0, duration, trackHeight - 1);//draw right end boundary

// g.DrawText(title, stringFont, Color.White, new PointF(duration + 4, 3));
// g.DrawTextSafe(title, stringFont, Color.White, new PointF(duration + 4, 3));
});

return bmp;
Expand Down Expand Up @@ -1599,7 +1599,7 @@ public static Image<Rgb24> DrawTimeTrack(TimeSpan duration, int width)
{
int secs = (int)Math.Round(x * secondsPerPixel);
TimeSpan span = new TimeSpan(0, 0, secs);
g.DrawText(span.ToString(), font, Color.Black, new PointF(x + 1, 3));
g.DrawTextSafe(span.ToString(), font, Color.Black, new PointF(x + 1, 3));
prevLocation = x;
}
}
Expand Down Expand Up @@ -1643,15 +1643,15 @@ public static Image<Rgb24> DrawShortTimeTrack(TimeSpan offsetMinute, TimeSpan xA
int minutes = totalSeconds / 60;
int seconds = totalSeconds % 60;
string time = $"{minutes}m{seconds}s";
g.DrawText(time, stringFont, Color.Black, new PointF(x + 1, 1)); //draw time
g.DrawTextSafe(time, stringFont, Color.Black, new PointF(x + 1, 1)); //draw time
}
}
}

g.DrawLine(blackPen, 0, 0, trackWidth, 0); //draw upper boundary
g.DrawLine(blackPen, 0, trackHeight - 1, trackWidth, trackHeight - 1); //draw lower boundary
g.DrawLine(blackPen, trackWidth, 0, trackWidth, trackHeight - 1); //draw right end boundary
g.DrawText(title, stringFont, Color.Black, new PointF(1, 1));
g.DrawTextSafe(title, stringFont, Color.Black, new PointF(1, 1));
});

return bmp;
Expand Down

0 comments on commit 5547a62

Please sign in to comment.