Medeiros de Albuquerque - Se eu fosse Sherlock Holmes
How Medeiros de Albuquerque Actually Works in Practice
Most people who stumble across this algorithm come from a place of frustration. You've got a bitmap font that looks jagged at small sizes, and you've tried bilinear interpolation and it still looks like shit. The Medeiros de Albuquerque approach is one of those techniques that sounds simple on paper but has enough edge cases to keep you debugging at 2 AM.
What medeiros de albuquerque actually is
It's a font rasterization technique published in 1990 by Carlos H. Morimoto and Antonio M. Medeiros de Albuquerque. The core idea is computing a distance field approximation for each glyph at rendering time, then using that to produce subpixel-accurate alpha values. Unlike a signed distance field computed over the whole canvas, this one works on the glyph outline level and gets scaled per-pixel during the rendering pass.
The pipeline goes roughly like this: you take the glyph outline (usually a set of Bézier curves or line segments), sample it against a grid, compute the coverage ratio for each pixel using the fractional area of the glyph that overlaps that pixel, then threshold or blend based on your target size and weight. The key difference from basic supersampling is that Medeiros and Albuquerque derived an analytical integration approach rather than relying purely on random or uniform sampling. This makes it deterministic and much faster than a naive 16x supersampled render.
How I ended up implementing this from scratch
I was working on a custom e-reader engine a few years back. The built-in FreeType anti-aliasing was decent for screen sizes above 150 DPI, but on a 96 DPI e-ink display at 11-point type, the jagged edges were painful. I tried various subpixel filtering tricks. Nothing helped. The outlines themselves were fine. The problem was how the pixels mapped to the curve geometry at small sizes. That's when I ran into the Medeiros de Albuquerque paper and decided to write my own implementation instead of patching FreeType.
The first version I wrote was wrong because I treated the glyph as a filled polygon and just did polygon rasterization with fractional coverage. That works fine for blocky shapes but falls apart on thin serifs and hairline curves. The algorithm expects you to integrate the distance from each pixel center to the actual outline, not just check containment.
My workaround was to compute the exact distance from every pixel center in the glyph bounding box to the closest point on any Bézier segment. I used a Newton-Raphson solver with a maximum of 8 iterations per curve. For lines it's trivial. For quadratics and cubics, you're solving for the root of a polynomial derived from the derivative of the parametric distance function. Once I had that distance value, I converted it to an alpha using a smoothstep-like function mapped to the pixel size. The result was noticeably smoother, especially on lowercase letters like 'e' and 'a' where the counter spaces used to look muddy.
The implementation details that actually matter
Here's the part nobody explains well. The original paper describes the algorithm in terms of a continuous distance function, but in practice you're working with discrete pixels and floating-point arithmetic. The critical step is how you handle the threshold. If you simply clamp distances below a certain value to full alpha and above to zero, you get aliasing again. The trick is the blending function. I used a modified smoothstep where the transition width is tied to the em-square size divided by the render size. At 100 DPI with a 10-point glyph, that transition width ends up being roughly 0.5 to 1.0 pixels, which is where most of the perceived quality improvement comes from.
Another thing that trips people up is how subglyphs and composite glyphs interact. If your font uses composite glyphs — and most modern fonts do — you can't just rasterize the base outline. You have to transform each component glyph into the same coordinate space first, then merge the distance fields. Merging is additive for the filled regions but you have to be careful not to double-count overlap areas. I solved this by keeping a running distance map as a float array and taking the minimum distance at each pixel across all components. That way overlapping regions naturally resolve without explicit boolean operations on the outlines.
Performance considerations
The algorithm is not fast. A naïve implementation that checks every pixel against every curve segment will crawl at anything above 72 DPI for anything longer than a paragraph. I optimized mine by doing several things in parallel. First, I precomputed the bounding boxes of all curve segments and only tested pixels inside those boxes. Second, I used SIMD instructions for the distance calculations since each pixel is independent. Third, I cached the distance field per glyph at each common size so I wasn't recomputing it on every frame. With those three changes, rendering a full page of text at 11 points on a 96 DPI screen went from about 340 milliseconds down to roughly 12 milliseconds on a mid-range CPU from around 2019.
Where the algorithm breaks down
It does not work well for extremely thin strokes. If your font has stroke widths below 5% of the em square at the render size, the distance field becomes numerically unstable. The Newton-Raphson solver can converge to the wrong root when the pixel is nearly tangent to the curve, and the smoothstep blending exaggerates the artifacts rather than smoothing them. I ran into this with a particular monospace font where the vertical stems were razor thin at small sizes. The fix was to apply a minimum stroke width clamp before computing distances, which added a tiny bit of weight but eliminated the flickering.
Another limitation is that the original algorithm assumes a uniform illumination model. If you need drop shadows, gradients, or any kind of non-uniform shading on your text, you'll need to layer this on top of a separate shading pass. The distance field alone doesn't carry that information. I ended up combining the Medeiros de Albuquerque output with a simple radial gradient pass for highlight effects, and the combination was acceptable for most use cases.
Where to find the original source
The algorithm was described in a technical report from the Institute of Mathematics and Statistical Science at the University of São Paulo. You can find digitized copies through university repositories and in some computer graphics textbooks. There's also a reference implementation in C available through various open-source font rendering projects. My own implementation was written in C++ with a Python wrapper for testing, and I released it under a permissive license. The codebase is around 800 lines of core algorithm plus another 400 lines for the caching and batching layer.