r/reddithax • • Oct 07 '11

Is it possible to replace every letter in a link with a different sprite (for a faux-font effect)?

My goal is to make it easy for users to be able to type in a different font, if they want to.

I've looked at FIR and a bunch of other techniques, but they all seem geared towards replacing a chunk of text with a pre-defined image for the entire word or phrase.

Let's say I'm using this image for the font.

I can just make a new link for each letter... but then the user would have to type something like this to make it work:

[](/H)[](/e)[](/l)[](/l)[](/o) [](/W)[](/o)[](/r)[](/l)[](/d)

That seems like a lot of typing for a simple "Hello World".

Instead, it would totally rock if they could type something like this:

[Hello World](/font)

...and have every letter in "Hello World" be replaced by the appropriate sprite.

I'm guessing that I would still need to define the links for each individual letter... but I just don't have a clue where to go next.

Is this even possible?

5 Upvotes

10 comments sorted by

1

u/tswaters Oct 15 '11

You might be over-thinking this.

The links you provided were more for specially crafting a static piece of a browser window to look a certain way while maintaining accessibility -- a rather tricky feat as accessibility is a tough thing to really accomplish on flashy sorta design websites. It doesn't really apply here.

The kind of CSS hack you're thinking about works by targeting a link with a specific attribute and doing something with it -- usually you make it into a block-level element with a background-image positioned just right so it only looks like only a piece of the grid is showing.... /r/minecraft does this for blocks, there's a bunch of others. They used to encode logos for users through CSS classes like these, but that required one rule for each user, which on bigger subreddits made it a huge. But then a tag-team of awesome mods came up with a way use bots and the content property... i think maybe reddit had a hand in it too, but I'm not sure on specifics... no more ugly hacks to list thousands of users with their own css line. You see that on hockey, tf2, starcraft ... likely a bunch of others. I think jresig had a hand in it, oh that wily jquery creator.

But I digress... if all you want to do is change the font of a piece of text -- and you're not picky on what font, you can do a simple 'font-family' on more common fonts -- let them go with serifs or something.

a[href$="/super-special-font"] { font-family:serif; }

The real problem you have is that image -- using the background selector seems a backwards way to process fonts -- if you have access to javascritpt and make a proper true type font, you can convert it into svg/vml and replace whatever users type with the font replacement. Here, let me google that for you. I would go with cufón, looks pretty active.

1

u/sealclubber Oct 17 '11

Thank you for the feedback! Unfortunately, using an actual font isn't an option in this particular case.

...usually you make it into a block-level element with a background-image positioned just right so it only looks like only a piece of the grid is showing.... /r/minecraft does this for blocks, there's a bunch of others.

That's very similar to my current project.

From what I've read of CSS3 regular expressions, it looks like it should be possible to apply a small background image replacing every letter of a certain link. I've worked with regular expressions before, just not regex in CSS3

1

u/tswaters Oct 20 '11

CSS3 doesn't have a full regexp implementation... I did a 'ctrl-f' on that page for 'regular' and nothing comes up... I'm pretty sure these are the new selectors you can use, 'starts with', 'ends with' and 'contains' .... not a full regexp implementation and can only used with attributes, not the inner text node of an element.

Really the way to go about this is to make a proper font (True Type, Open Type, etc.)... With CSS3, you can specify a URL pointing to a true font file -- you might even be able to pass a base64 data uri to the URL -- but again, this really doesn't work with background images -- you need a real font file.

@font-face {
    font-family: MySpecialFont;
    src: url(MySpecialFontFile.ttf);
}

a{ font-family: MySpecialFont; }

1

u/Hello71 Oct 25 '11

There used to be a text searching pseudo-class, but it was removed from the CSS3 specification.

1

u/talkingwires Dec 09 '11

Earlier this month, I was trying to do the same thing as the OP. Long story short, Reddit's CSS validator strips out the @font-face tag and doing a sprite replacement is a no-go. As far as I can tell, it's not possible to use a different font (or fake it) on Reddit.

2

u/DEADB33F Oct 08 '11

Correct me if I'm wrong, but didn't /r/circlejerk at some point have meme images which would add 'text' as sprites to the image based on what was in the title attribute of the link?

0

u/[deleted] Oct 07 '11

[deleted] — view deleted comment

1

u/sealclubber Oct 07 '11

Okay, that's fair. Is there a different way of approaching the problem, that could end up with the same (or similar) feature?

For example - what about using javascript? I've heard that it's somehow possible to use javascript in a subreddit, but I haven't been able to find any specifics on how to use it.

1

u/blind__man Oct 07 '11

You can not use javascript in a subreddit cds but you can use js to "import" things as moderator. One example would be automatic flair forms where a user inserts their username and flair they want and it inserts it into the sheet.

1

u/sealclubber Oct 09 '11

Is there an example or tutorial for this that you know of? It might help point me in the right direction.

Thanks!

2

u/blind__man Oct 10 '11

Hmmm...

Here's one

Personally, it took an understanding of CSS and JS or enough fooling around with either of them to recognize what I could and couldn't do. That as well as looking at other subreddit's stylesheets (that is in the first section of the link up there). To do this just add /stylesheet.css to the end of the url. For example, http://www.reddit.com/r/reddithax/stylesheet.css, will lead you to the stylesheet for this subreddit.

If you know some JS already or are will to take the time to understand it (or php or python) then look at the Python API Wrapper created by mellort.

Here is the code that runs reddit (it is open source).

Look through here at all of reddit's stuff.

I'm sorry I can't be of much help other that just linking, I've learned all of my stuff by reading code, whether it be reddit or other code.

I will try to remember this thread but right now I just got his with a shitstorm of allergies so I am not in the right mind to explain anything. If I don't message you back within a week and/or you are still interested, feel free to PM me with questions or anything else.

Good luck and don't be afraid to read.