string-pixel-width | Blazingly fast measure string width in pixels | Runtime Evironment library

 by   adambisek JavaScript Version: 1.11.0 License: No License

kandi X-RAY | string-pixel-width Summary

kandi X-RAY | string-pixel-width Summary

string-pixel-width is a JavaScript library typically used in Server, Runtime Evironment, React Native, React, Nodejs, NPM applications. string-pixel-width has no bugs, it has no vulnerabilities and it has low support. You can install using 'npm i string-pixel-width' or download it from GitHub, npm.

Blazingly fast measure string width in pixels on the server in Javascript (Node.Js)
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              string-pixel-width has a low active ecosystem.
              It has 82 star(s) with 29 fork(s). There are 3 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 5 open issues and 4 have been closed. On average issues are closed in 11 days. There are 13 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of string-pixel-width is 1.11.0

            kandi-Quality Quality

              string-pixel-width has 0 bugs and 0 code smells.

            kandi-Security Security

              string-pixel-width has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              string-pixel-width code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              string-pixel-width does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              string-pixel-width releases are available to install and integrate.
              Deployable package is available in npm.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of string-pixel-width
            Get all kandi verified functions for this library.

            string-pixel-width Key Features

            No Key Features are available at this moment for string-pixel-width.

            string-pixel-width Examples and Code Snippets

            No Code Snippets are available at this moment for string-pixel-width.

            Community Discussions

            QUESTION

            Measuring the height of text according to CSS rules – _without a browser rendering_ – for use with a virtualized list, to specify heights in advance
            Asked 2019-Dec-28 at 13:55

            I've been implementing a chat client in Electron (Chrome) and React. Our top priority is speed. It behooves us, then, to use a virtualized list component (also known as "buffered render" or "window render"). We've explored react-virtualized, react-window, and react-infinite, among others.

            One issue all these components have in common is that if supporting list elements of variable heights, the heights need to be known in advance. Now, some chats are very long, and others are very short, so that presents a challenge for us. (Images and video are easy thanks to EXIF data and ffprobe).

            So, we're faced with the challenge of measuring heights while also straining to be extremely performant. One obvious technique is to put the elements in a browser container off-viewport, perform the measurements, and then render the list. But that hurts us on the performance requirement aspect. Software like react-virtualized/CellMeasurer (which is no longer maintained by the original author) and react-window make us of this technique, built in to the library, but performance is somewhat slow as well as unreliable. A similar idea that might be more performant would be to use a background Electron Browser window to do the rendering and measuring, but my intuition is that wouldn't be that much faster.

            I submit that there must be some solved way to figure out string height in advance, according to word wrap, max width, and font rules.

            My current idea is to use a library like string-pixel-width in order to calculate row heights as soon as we get the text data through our API. Basically, the library uses this piece of code to generate a map of character widths [*]. Then, once we know how wide each text, we separate each line when it maxes out the computed max row width, and finally infer list element height through row count. It's going to require a little bit of algorithmic fiddling due to break-word but there are libraries to help with that – css-line-break seems promising.

            [*] We would have to modify it a bit to account for all Unicode character ranges, but that is trivial.

            Some options I haven't fully explored yet include the python weasyprint project and the facebook-yoga project. I'm open to your ideas!

            ...

            ANSWER

            Answered 2019-Dec-28 at 13:55

            Using the canvas capabilities to measure text could solve this problem in a performant way.

            Electrons canvas text is calculated the same as the regular text, there are some diffrences in rendering though especially in reguard of anti-aliasing but that does not affect the calculation.

            You can get the TextMetrics from any text with

            Source https://stackoverflow.com/questions/59440762

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install string-pixel-width

            You can install using 'npm i string-pixel-width' or download it from GitHub, npm.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i string-pixel-width

          • CLONE
          • HTTPS

            https://github.com/adambisek/string-pixel-width.git

          • CLI

            gh repo clone adambisek/string-pixel-width

          • sshUrl

            git@github.com:adambisek/string-pixel-width.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link