iOfficeAI/OfficeCLI · error · ArgumentException
Invalid font size: '{value}'. Minimum font size is 0.5pt (on
Error message
Invalid font size: '{value}'. Minimum font size is 0.5pt (one half-point). What it means
Thrown by ParseFontSize when the size is positive but below 0.5pt. OOXML stores font size as half-points (w:sz must be >= 1), so anything below 0.5pt would round to val=0 on write and produce schema-invalid OOXML that Word rejects. The library rejects up front with the same message shape as the other guards.
Source
Thrown at src/officecli/Core/ParseHelpers.cs:375
/// Returns double to preserve fractional sizes for correct unit conversion.
/// </summary>
public static double ParseFontSize(string value)
{
var trimmed = value.Trim();
if (trimmed.EndsWith("pt", StringComparison.OrdinalIgnoreCase))
trimmed = trimmed[..^2].Trim();
if (trimmed.Contains(','))
throw new ArgumentException($"Invalid font size: '{value}'. Comma is not allowed — use '.' as decimal separator (e.g., '10.5').");
if (!double.TryParse(trimmed, CultureInfo.InvariantCulture, out var result) || double.IsNaN(result) || double.IsInfinity(result))
throw new ArgumentException($"Invalid font size: '{value}'. Expected a finite number (e.g., '12', '10.5', '14pt').");
if (result <= 0)
throw new ArgumentException($"Invalid font size: '{value}'. Font size must be greater than 0.");
// OOXML w:sz/w:szCs/w:fontSize are half-points and must be >= 1.
// Anything below 0.5pt would round to val=0 on write, producing
// schema-invalid OOXML. Reject up front with the same shape as
// the "<= 0" guard above.
if (result < 0.5)
throw new ArgumentException($"Invalid font size: '{value}'. Minimum font size is 0.5pt (one half-point).");
// OOXML caps user-entered font size at 1638pt (Word) and Office
// renderers stop honoring values past ~4000pt anyway. Anything
// larger silently overflows the int32 the writers cast to (PPTX
// writes pt × 100, Word writes pt × 2 as half-points), producing
// negative w:sz / a:rPr@sz values Word rejects on open. Reject
// up front with the same shape as the lower-bound guards.
if (result > 4000)
throw new ArgumentException($"Invalid font size: '{value}'. Maximum font size is 4000pt (Office cap).");
return result;
}
/// <summary>
/// BUG-R4B(BUG1): Leniently parse an integer-valued OOXML attribute that
/// some producers emit with a fractional part (e.g. <c>w:w="0.0"</c> /
/// <c>w:w="9440.0"</c>). The Open XML SDK's typed accessors (e.g.
/// <c>Int32Value.Value</c>) parse the raw string lazily and throw a bare
/// <see cref="FormatException"/> ("The input string '0.0' was not in a
/// correct format") the first time the value is read. Reading the rawView on GitHub (pinned to 1ced45e900)
Solutions
- Use a size of at least 0.5pt.
- Clamp the computed size: Math.Max(pts, 0.5).
- Re-check scale factors that can shrink text below readable sizes.
Example fix
// before var pts = baseSize * 0.01; // -> 0.12 ParseFontSize(pts.ToString(CultureInfo.InvariantCulture)); // throws 295 // after var pts = Math.Max(baseSize * 0.01, 0.5); ParseFontSize(pts.ToString(CultureInfo.InvariantCulture));
Defensive patterns
Strategy: validation
Validate before calling
const double MinPt = 0.5; pts = Math.Max(pts, MinPt);
Type guard
static bool IsAtLeastHalfPoint(double v) => v >= 0.5 && !double.IsNaN(v) && !double.IsInfinity(v);
Try / catch
try { pts = ParseFontSize(s); }
catch (ArgumentException ex) when (ex.Message.Contains("0.5pt"))
{ pts = 0.5; } Prevention
- Clamp computed sizes to >= 0.5pt.
- Re-check scale factors that can shrink text below readable sizes.
- Unit-test the lower boundary explicitly.
When it happens
Trigger: Passing "0.25" or "0.3". A fractional size from a scaling factor that shrank the font below half a point.
Common situations: Responsive/scaling code that multiplies by a small factor; converting from a unit where the result is sub-half-point; debug values entered during testing.
Related errors
- Invalid font size: '{value}'. Maximum font size is 4000pt (O
- Invalid font size: '{value}'. Font size must be greater than
- Invalid range '{spec}': offsets must be non-negative.
- Invalid color transform '{token}': raw value {raw} out of ra
- Invalid color value: '{original}'. RGB percentage components
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/8b118106b89fb5a4.
Report an issue: GitHub.