{"record":{"id":"e0383f245cccfcba","repo":"dotnet/wpf","slug":"sr-charactermetrics-negativeverticaladvance","errorCode":null,"errorMessage":"SR.CharacterMetrics_NegativeVerticalAdvance","messagePattern":"SR\\.CharacterMetrics_NegativeVerticalAdvance","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetrics.cs","lineNumber":110,"sourceCode":"                CompositeFontParser.VerifyNonNegativeMultiplierOfEm(nameof(BlackBoxWidth), ref metrics[(int)FieldIndex.BlackBoxWidth]);\n                CompositeFontParser.VerifyNonNegativeMultiplierOfEm(nameof(BlackBoxHeight), ref metrics[(int)FieldIndex.BlackBoxHeight]);\n                CompositeFontParser.VerifyMultiplierOfEm(nameof(Baseline), ref metrics[(int)FieldIndex.Baseline]);\n                CompositeFontParser.VerifyMultiplierOfEm(nameof(LeftSideBearing), ref metrics[(int)FieldIndex.LeftSideBearing]);\n                CompositeFontParser.VerifyMultiplierOfEm(nameof(RightSideBearing), ref metrics[(int)FieldIndex.RightSideBearing]);\n                CompositeFontParser.VerifyMultiplierOfEm(nameof(TopSideBearing), ref metrics[(int)FieldIndex.TopSideBearing]);\n                CompositeFontParser.VerifyMultiplierOfEm(nameof(BottomSideBearing), ref metrics[(int)FieldIndex.BottomSideBearing]);\n\n                double horizontalAdvance = metrics[(int)FieldIndex.BlackBoxWidth]\n                    + metrics[(int)FieldIndex.LeftSideBearing]\n                    + metrics[(int)FieldIndex.RightSideBearing];\n                if (horizontalAdvance < 0)\n                    throw new ArgumentException(SR.CharacterMetrics_NegativeHorizontalAdvance);\n\n                double verticalAdvance = metrics[(int)FieldIndex.BlackBoxHeight]\n                    + metrics[(int)FieldIndex.TopSideBearing]\n                    + metrics[(int)FieldIndex.BottomSideBearing];\n                if (verticalAdvance < 0)\n                    throw new ArgumentException(SR.CharacterMetrics_NegativeVerticalAdvance);\n\n                // Set all the properties.\n                _blackBoxWidth = metrics[(int)FieldIndex.BlackBoxWidth];\n                _blackBoxHeight = metrics[(int)FieldIndex.BlackBoxHeight];\n                _baseline = metrics[(int)FieldIndex.Baseline];\n                _leftSideBearing = metrics[(int)FieldIndex.LeftSideBearing];\n                _rightSideBearing = metrics[(int)FieldIndex.RightSideBearing];\n                _topSideBearing = metrics[(int)FieldIndex.TopSideBearing];\n                _bottomSideBearing = metrics[(int)FieldIndex.BottomSideBearing];\n            }\n        }\n\n        private static void AppendField(double value, FieldIndex fieldIndex, ref int lastIndex, StringBuilder s)\n        {\n            if (value != 0)\n            {\n                s.Append(',', (int)fieldIndex - lastIndex);\n                lastIndex = (int)fieldIndex;","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetrics.cs#L92-L128","documentation":"CharacterMetrics' constructor also computes verticalAdvance = BlackBoxHeight + TopSideBearing + BottomSideBearing and throws ArgumentException (SR.CharacterMetrics_NegativeVerticalAdvance) when that sum is negative, since a glyph's vertical advance cannot be negative in this model.","triggerScenarios":"Constructing CharacterMetrics from a string where BlackBoxHeight plus top/bottom side bearings totals below zero.","commonSituations":"Corrupt or hand-edited composite font metric sections; automated metric extraction writing negative heights; copy/paste sign errors in font metadata files.","solutions":["Fix the metrics string so BlackBoxHeight + TopSideBearing + BottomSideBearing >= 0.","Sanitize/clamp negative vertical bearings in the data source.","Regenerate metrics from the actual font rather than editing them manually."],"exampleFix":"// before\nvar m = new CharacterMetrics(\"0,0,0,10,-10,0\"); // negative vertical advance\n\n// after\nvar m = new CharacterMetrics(\"0,0,0,10,0,0\");","handlingStrategy":"validation","validationCode":"static bool HasValidVerticalAdvance(double blackBoxHeight, double top, double bottom)\n    => blackBoxHeight + top + bottom >= 0;","typeGuard":null,"tryCatchPattern":"try { var m = new CharacterMetrics(str); }\ncatch (ArgumentException ex) { Log(ex.Message); m = CharacterMetrics.Default; }","preventionTips":["Check BlackBoxHeight + TopSideBearing + BottomSideBearing >= 0 before construction.","Clamp negative vertical bearings in the metrics source.","Regenerate metrics from font files instead of manual edits."],"tags":["wpf","typography","argument-exception","metrics"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}