GithubHelp home page GithubHelp logo

mbrubeck / robinson Goto Github PK

View Code? Open in Web Editor NEW
1.5K 35.0 133.0 219 KB

A toy web rendering engine

Home Page: http://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html

License: MIT License

Rust 100.00%

robinson's Introduction

Robinson

A toy web rendering engine written in the Rust language, by Matt Brubeck ([email protected]).

I'm writing this code purely for educational purposes. My goal is to create an incomplete but extremely simple engine as a way to learn more about basic implementation techniques, without worrying about complications like:

  • Real-world usability
  • Standards compliance
  • Performance and efficiency
  • Interoperability

These are all important goals, but there are other projects working on them. By ignoring them completely, this project can focus on being as simple and easy-to-understand as possible.

Why create a simple—but useless—toy rendering engine? Mostly because I personally want to learn how to do it. If I succeed, I also hope that other people can learn from my code by reading or modifying it, or learn from my experience as they set out to build their own toy browser engines.

For more details see Let's build a browser engine!, a series of how-to articles based on this project.

Status

Currently implemented:

  • Parse a small subset of HTML and build a DOM tree.
  • Parse a small subset of CSS.
  • Perform selector matching to apply styles to elements.
  • Basic block layout.

Coming soon, I hope:

  • Inline layout.
  • Paint text and boxes.
  • Load resources from network or filesystem.

Instructions

  1. Install Rust 1.0 beta or newer.

  2. Clone the robinson source code from https://github.com/mbrubeck/robinson

  3. Run cargo build to build robinson, and cargo run to run it.

To build and run with optimizations enabled, use cargo build --release and cargo run --release.

By default, robinson will load test.html and test.css from the examples directory. You can use the --html and --css arguments to the robinson executable to change the input files:

./target/debug/robinson --html examples/test.html --css examples/test.css

The rendered page will be saved to a file named output.png. To change the output filename, use the -o option. To switch to PDF output, use add --format pdf.

robinson's People

Contributors

addyosmani avatar aethanyc avatar anuragsoni avatar cybai avatar dhodder avatar luisbg avatar mbrubeck avatar pbondoer avatar sanxiyn avatar seanjensengrey avatar simonsapin avatar zachwick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

robinson's Issues

Unable to build rustc-serialize

Rust Version Cargo Version
rustc 1.0.0-nightly (458a6a2f6 2015-01-25 21:20:37 +0000) cargo 0.0.1-pre-nightly (bb28e71 2015-01-22 06:06:34 +0000)

I'm getting this error when running cargo build:

   Compiling rustc-serialize v0.2.7
   Compiling getopts v0.1.4
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/base64.rs:207:5: 209:6 error: method `detail` is not a member of trait `error::Error`
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/base64.rs:207     fn detail(&self) -> Option<String> {
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/base64.rs:208         Some(format!("{:?}", self))
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/base64.rs:209     }
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/hex.rs:91:5: 93:6 error: method `detail` is not a member of trait `error::Error`
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/hex.rs:91     fn detail(&self) -> Option<String> {
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/hex.rs:92         Some(format!("{:?}", self))
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/hex.rs:93     }
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/json.rs:336:5: 336:84 error: method `detail` is not a member of trait `std::error::Error`
/home/bsve/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.2.7/src/json.rs:336     fn detail(&self) -> Option<std::string::String> { Some(format!("{:?}", self)) }
                                                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
Build failed, waiting for other jobs to finish...
Could not compile `rustc-serialize`.

To learn more, run the command again with --verbose

I'm sorry if this issue does not belong here as it seems to be an dependency issue.
However, I tried to clone rustc-serialize (albeit v0.2.9) and built it without any errors.

fails to build

I have rustc 0.11.0 installed and I get this output from make:

src/dom.rs:47:5: 49:6 note: consider using an explicit lifetime parameter as shown: fn get_attribute<'a>(&'a self, key: &str) -> Option<&'a String>
src/dom.rs:47     pub fn get_attribute(&self, key: &str) -> Option<&String> {
src/dom.rs:48         self.attributes.find_equiv(&key)
src/dom.rs:49     }
src/dom.rs:48:9: 48:41 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
src/dom.rs:48         self.attributes.find_equiv(&key)
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/layout.rs:48:5: 54:6 note: consider using an explicit lifetime parameter as shown: fn new<'b>(box_type: BoxType<'b>) -> LayoutBox<'b>
src/layout.rs:48     fn new(box_type: BoxType) -> LayoutBox {
src/layout.rs:49         LayoutBox {
src/layout.rs:50             box_type: box_type,
src/layout.rs:51             dimensions: Default::default(),
src/layout.rs:52             children: Vec::new(),
src/layout.rs:53         }
                 ...
src/layout.rs:49:9: 53:10 error: cannot infer an appropriate lifetime for lifetime parameter `'a due to conflicting requirements
src/layout.rs:49         LayoutBox {
src/layout.rs:50             box_type: box_type,
src/layout.rs:51             dimensions: Default::default(),
src/layout.rs:52             children: Vec::new(),
src/layout.rs:53         }
src/layout.rs:244:5: 257:6 note: consider using an explicit lifetime parameter as shown: fn get_inline_container<'b>(&'b mut self) -> &'b mut LayoutBox<'a>
src/layout.rs:244     fn get_inline_container(&mut self) -> &mut LayoutBox<'a> {
src/layout.rs:245         match self.box_type {
src/layout.rs:246             InlineNode(_) | AnonymousBlock => self,
src/layout.rs:247             BlockNode(_) => {
src/layout.rs:248                 // If we've just generated an anonymous block box, keep using it.
src/layout.rs:249                 // Otherwise, create a new one.
                  ...
src/layout.rs:254:17: 254:41 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
src/layout.rs:254                 self.children.mut_last().unwrap()
                                  ^~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:22:27: 22:38 error: type `getopts::Fail_` does not implement any method in scope named `to_string`
src/main.rs:22         Err(f) => fail!(f.to_string())
                                         ^~~~~~~~~~~
src/main.rs:31:38: 31:54 error: type `core::result::Result<std::io::fs::File,std::io::IoError>` does not implement any method in scope named `read_to_string`
src/main.rs:31         File::open(&Path::new(path)).read_to_string().unwrap()
                                                    ^~~~~~~~~~~~~~~~
error: aborting due to 5 previous errors
Makefile:249: recipe for target 'bin/main' failed
make: *** [bin/main] Error 101

I would try to debug, but I'm trying to learn Rust and browser engines so it's all new to me.

Unable to Cargo Run --release

[censored]>cargo run --release
Finished release [optimized] target(s) in 0.12s
Running [censored]\robinson-master\robinson-master\target\rel ease\robinson.exe
thread 'main' panicked at 'called Result::unwrap() on an Err value: Os { cod
e: 3, kind: NotFound, message: "The system cannot find the path specified." }',
libcore\result.rs:945:5
note: Run with RUST_BACKTRACE=1 for a backtrace.
error: process didn't exit successfully: [censored]\robinson-maste r\robinson-master\target\release\robinson.exe (exit code: 101)

I wish I had written below. :(

I wish I had written below. :(
1-) If either c was written in c ++ or python. now i will learn rust but i get
2-) I would like to add a screenshot or Intro video

Fix clippy warnings

This will make the already very educational code more readable.

Please tag this issue as 'Hacktoberfest' 😄

Thanks so much for your "Let's build a browser engine!" series. Really cool.

Error in css.rs with latest rust

Using bebcebc and running make with rustc 0.12.0-nightly (dc987adfc 2014-10-04 23:42:07 +0000), the following error occurs:

src/css.rs:185:16: 185:18 error: expected `=>`, found `..`
src/css.rs:185             '0'..'9' => self.parse_length(),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.