Passed
Push — master ( 303aeb...9daf35 )
by Roeland
10:44 queued 10s
created
lib/private/Preview/TXT.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -34,74 +34,74 @@
 block discarded – undo
34 34
 use OCP\IImage;
35 35
 
36 36
 class TXT extends ProviderV2 {
37
-	/**
38
-	 * {@inheritDoc}
39
-	 */
40
-	public function getMimeType(): string {
41
-		return '/text\/plain/';
42
-	}
43
-
44
-	/**
45
-	 * {@inheritDoc}
46
-	 */
47
-	public function isAvailable(FileInfo $file): bool {
48
-		return $file->getSize() > 0;
49
-	}
50
-
51
-	/**
52
-	 * {@inheritDoc}
53
-	 */
54
-	public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
55
-		$content = $file->fopen('r');
56
-
57
-		if ($content === false) {
58
-			return null;
59
-		}
60
-
61
-		$content = stream_get_contents($content,3000);
62
-
63
-		//don't create previews of empty text files
64
-		if(trim($content) === '') {
65
-			return null;
66
-		}
67
-
68
-		$lines = preg_split("/\r\n|\n|\r/", $content);
69
-
70
-		// Define text size of text file preview
71
-		$fontSize = $maxX ? (int) ((1 / 32) * $maxX) : 5; //5px
72
-		$lineSize = ceil($fontSize * 1.5);
73
-
74
-		$image = imagecreate($maxX, $maxY);
75
-		imagecolorallocate($image, 255, 255, 255);
76
-		$textColor = imagecolorallocate($image, 0, 0, 0);
77
-
78
-		$fontFile  = __DIR__;
79
-		$fontFile .= '/../../../core';
80
-		$fontFile .= '/fonts/NotoSans-Regular.ttf';
81
-
82
-		$canUseTTF = function_exists('imagettftext');
83
-
84
-		foreach($lines as $index => $line) {
85
-			$index = $index + 1;
86
-
87
-			$x = (int) 1;
88
-			$y = (int) ($index * $lineSize);
89
-
90
-			if ($canUseTTF === true) {
91
-				imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontFile, $line);
92
-			} else {
93
-				$y -= $fontSize;
94
-				imagestring($image, 1, $x, $y, $line, $textColor);
95
-			}
96
-
97
-			if(($index * $lineSize) >= $maxY) {
98
-				break;
99
-			}
100
-		}
101
-
102
-		$imageObject = new \OC_Image();
103
-		$imageObject->setResource($image);
104
-
105
-		return $imageObject->valid() ? $imageObject : null;
106
-	}
37
+    /**
38
+     * {@inheritDoc}
39
+     */
40
+    public function getMimeType(): string {
41
+        return '/text\/plain/';
42
+    }
43
+
44
+    /**
45
+     * {@inheritDoc}
46
+     */
47
+    public function isAvailable(FileInfo $file): bool {
48
+        return $file->getSize() > 0;
49
+    }
50
+
51
+    /**
52
+     * {@inheritDoc}
53
+     */
54
+    public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
55
+        $content = $file->fopen('r');
56
+
57
+        if ($content === false) {
58
+            return null;
59
+        }
60
+
61
+        $content = stream_get_contents($content,3000);
62
+
63
+        //don't create previews of empty text files
64
+        if(trim($content) === '') {
65
+            return null;
66
+        }
67
+
68
+        $lines = preg_split("/\r\n|\n|\r/", $content);
69
+
70
+        // Define text size of text file preview
71
+        $fontSize = $maxX ? (int) ((1 / 32) * $maxX) : 5; //5px
72
+        $lineSize = ceil($fontSize * 1.5);
73
+
74
+        $image = imagecreate($maxX, $maxY);
75
+        imagecolorallocate($image, 255, 255, 255);
76
+        $textColor = imagecolorallocate($image, 0, 0, 0);
77
+
78
+        $fontFile  = __DIR__;
79
+        $fontFile .= '/../../../core';
80
+        $fontFile .= '/fonts/NotoSans-Regular.ttf';
81
+
82
+        $canUseTTF = function_exists('imagettftext');
83
+
84
+        foreach($lines as $index => $line) {
85
+            $index = $index + 1;
86
+
87
+            $x = (int) 1;
88
+            $y = (int) ($index * $lineSize);
89
+
90
+            if ($canUseTTF === true) {
91
+                imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontFile, $line);
92
+            } else {
93
+                $y -= $fontSize;
94
+                imagestring($image, 1, $x, $y, $line, $textColor);
95
+            }
96
+
97
+            if(($index * $lineSize) >= $maxY) {
98
+                break;
99
+            }
100
+        }
101
+
102
+        $imageObject = new \OC_Image();
103
+        $imageObject->setResource($image);
104
+
105
+        return $imageObject->valid() ? $imageObject : null;
106
+    }
107 107
 }
Please login to merge, or discard this patch.