Skip to content

Instantly share code, notes, and snippets.

@raphlinus
raphlinus / harfbuzz-boom.rs
Created March 13, 2019 23:36
Example of unsoundness in harfbuzz crate
use harfbuzz::Blob;
fn create_blob() -> Blob {
let vec = vec![1; 256];
Blob::new_read_only(&vec)
// BAD: vec is dropped here, the blob still holds a reference
}
fn blob_sum(blob: &Blob) -> u32 {
blob.iter().map(|byte| *byte as u32).sum()
@raphlinus
raphlinus / fallback.rs
Created March 29, 2019 20:37
example code for dwrote-rs to exercise fallback
extern crate dwrote;
extern crate winapi;
use std::borrow::Cow;
use winapi::um::dwrite::{DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, DWRITE_READING_DIRECTION,
DWRITE_READING_DIRECTION_LEFT_TO_RIGHT
};
use dwrote::{FontCollection, FontFallback, FontStretch, FontStyle, FontWeight, NumberSubstitution,
TextAnalysisSource, TextAnalysisSourceImpl,
@raphlinus
raphlinus / str_source.rs
Created April 25, 2019 15:42
Sketch of StrSource trait for access to string data
use std::borrow::Cow;
pub trait StrSource {
fn len(&self) -> usize;
fn str_at(&self, ix: usize) -> &str;
fn str_before(&self, ix: usize) -> &str;
fn to_string(&self) -> String {
@raphlinus
raphlinus / subpixel_antialias.py
Created May 1, 2019 13:59
Research code to do RGB subpixel antialiasing using angle info in signed distance fields
import math
# http://vcl.itn.liu.se/publications/2011/GS11/edtaa_preprint.pdf
def tex(df, cos_th):
cos_th = abs(cos_th)
sin_th = math.sqrt(1 - cos_th ** 2)
if cos_th < sin_th:
cos_th, sin_th = sin_th, cos_th
a1 = 0.5 * sin_th / cos_th # note: paper is missing the 0.5!
@raphlinus
raphlinus / README.md
Last active June 6, 2019 14:59
test of spline foo

scatter

This crate contains an implementation of Radial Basis Function multidimensional interpolation. For an excellent introduction to the topic, see the [SIGGRAPH 2014 course notes].

The input is a set of datapoints, each of which has coordinates in some multidimensional space, and a value, also provided as a vector. For example, for the colorfield images below, the coordinates are 2D, and the values are a 3-vector, one each for red, green, and blue. The result is a Scatter struct that can then be evaluated at any coordinate. The idea is that the values vary smoothly with the coordinates, but coincide with the input at each

@raphlinus
raphlinus / new_widget.rs
Created June 18, 2019 14:49
Very rough sketch of parent-owns widget scheme
// Sketch of new widget scheme for druid. Some pseudocode within.
/// Base of a widget.
///
/// Name should likely change, this name is chosen to express
/// what's actually in it.
pub struct Base<W: WidgetInner> {
state: BaseState,
inner: W,
@raphlinus
raphlinus / smooth.md
Created June 20, 2019 01:15
rough draft of smooth resizing post
layout title date categories
post
The smooth resize test
2019-06-17 07:26:42 -0700
rust
gui

When I was young, as we traveled my dad had a quick test for the quality of a Chinese restaurant: if the tea wasn't good, chances were the food wouldn't be great either. One time, we left before ordering, and I don't think we missed out on much.

Today is an exciting point in the evolution of native GUI in Rust. There is much exploration, and a number of promising projects, but I also think we don't yet know the recipe to make GUI truly great. As I develop my own vision in this space, [druid], I hope more that the efforts will learn from each other and that an excellent synthesis will emerge, more so than simply hoping that druid will win.

@raphlinus
raphlinus / lens.rs
Created July 5, 2019 20:19
Sketch of lens trait
pub trait Lens<T, U> {
fn get<'a>(&self, data: &'a T) -> &'a U;
fn with_mut<F: FnOnce(&mut U)>(&self, data: &mut T, f: F);
}
========================
creating window...
width: 1424
height: 704
tile_side_length_in_pixels: 8
per_tile_command_lists_num_tiles_per_tg_x: 32
per_tile_command_lists_num_tiles_per_tg_y: 1
num_tiles_x: 192
num_tiles_y: 88
canvas_quad_width: 1536
@raphlinus
raphlinus / AppDelegate.m
Created August 10, 2019 23:49
simple toy for inspecting pasteboard types
//
// AppDelegate.m
// Pasteboard toy
//
// Created by Raph Levien on 8/10/19.
// Copyright © 2019 Raph Levien. All rights reserved.
//
#import "AppDelegate.h"